Cordyceps cicadae is an entomogenous fungus with important uses in traditional Chinese medicine. However, its wild resources have not met consumers’ demand due to excessive harvesting practices. Artificial cultivation is therefore an important alternative, but research on cultivating C. cicadae in natural habitats has not been reported. In this study, we aimed to explore the viability of cultivating C. cicadae in a natural habitat, in the soil of Pinus massoniana forest. We assessed and compared the yield, metabolite contents and bacterial community composition of C. cicadae grown in the Antheraea pernyi pupae at different growth stages, and under different cultivation conditions, in the soil of a natural habitat and in sterile glass bottles. Our results showed that cultivating C. cicadae in a natural habitat is feasible, with up to 95% of pupae producing C. cicadae fruiting bodies. The content of nitrogen compounds (amino acids) in C. cicadae cultivated in a natural habitat was significantly higher than in glass bottles, while the yield and carbon compound (mannitol and polysaccharide) and nucleoside (cordycepin and adenosine) contents were lower. Different bacterial genera were enriched in C. cicadae at different growth stages and cultivation environments, and these bacterial genera were closely related to metabolites contents during growth. This study demonstrated the viability of a novel cultivation method of C. cicadae, which could be used as an alternative to wild stocks of this fungus. These findings provided new insights into the growth mechanism of C. cicadae and its interaction with soil microorganisms.