Microbes can be engineered to sense target chemicals for environmental and geospatial detection. However, when engineered microbes operate in real-world environments, it remains unclear how competition with natural microbes affect their performance over long time periods. Here, we engineer sensors and memory-storing genetic circuits inside the soil bacterium
Bacillus subtilis
to sense the TNT explosive and maintain a long-term response, using predictive models to design riboswitch sensors, tune transcription rates, and improve the genetic circuit’s dynamic range. We characterize the autonomous microbial sensor’s ability to detect TNT in a natural soil system, measuring single-cell and population-level behavior over a 28-day period. The autonomous microbial sensor activates its response by 14-fold when exposed to low TNT concentrations and maintains stable activation for over 21 days, exhibiting exponential decay dynamics at the population-level with a half-life of about 5 days. Overall, we show that autonomous microbial sensors can carry out long-term detection of an important chemical in natural soil with competitive growth dynamics serving as additional biocontainment.