Bacteria can be great little workhorses, engineered to make better batteries, clean up waste plastics, combat cancer and even produce oxygen for the first human settlers on Mars. The problem is, we don't really know what the crafty critters could do if they were to ever escape from their intended environments – and let's face it, they probably will. To keep the bugs in check, scientists from Harvard's Wyss Institute have developed two types of "kill switches" that can be embedded in their genomes.

The Harvard team is building on previous work, which developed ways to kill bacteria on demand when they were no longer needed, but that wouldn't be enough for real-world applications. The bacteria need to automatically self-destruct when they leave their working environment – in this case, the bodies of animals – and since microbes evolve so quickly, the scientists need to be sure that the kill switch genes are passed down to every generation.

The team calls the first kill switch the "Essentializer," because it prevents the bacteria from removing a certain feature from their genome through evolution. The Essentializer encodes for a gene that produces a toxin that will kill the bacteria if levels get too high, but bacteriophage factors in a "memory element" are constantly inhibiting expression of that toxin gene. That means the memory element is essential to the bacteria's survival, and if a random genetic mutation removed it, the bug dies.

"By tying the function of the memory element to that of the Essentializer, we basically link the survival of E. coli bacteria to the presence of the memory element," says Finn Stirling, first author of the study. "The removal of the memory element from the bacterial genome, which also eliminates the two toxin-suppressing phage factors, immediately triggers the kill switch to produce high amounts of toxin that overwhelm the anti-toxin and eliminate the affected bacteria from the population. To create this sophisticated system of checks and balances, we also made sure that the kill switches themselves remained fully intact, which is an important prerequisite for future applications; we verified that they were still functional after about 140 cell divisions."

The second kill switch, nicknamed "Cryodeath," works on the same principle, but in this case the toxin mechanism instantly kills the bacteria if it ever gets out of the body. That's done by making temperature the trigger: the toxin gene is only activated if the bacteria's surroundings drop from 37° C (98.6° F) – a regular body temperature – to 22° C (71.6° F). In tests in mice, the team introduced their kill switch-enabled E. coli and then tested the animals' feces for any surviving bugs. Only one bacterium in 100,000 was found to be still viable outside the body.

"This advance brings us significantly closer to real-world applications of synthetically engineered microbes in the human body or the environment," says Pamela Silver, lead researcher on the study. "We are now working toward combinations of kill switches that can respond to different environmental stimuli to provide even tighter control."

These kill switches could be just a couple of weapons in a wider arsenal against engineered bacteria going rogue. An MIT team developed a "deadman's switch" and a "passcode" that would instantly kill a bacteria if one or more chemicals were missing, while Caltech researchers used thermal "walkie talkies" to relay instructions to bacteria in the body about when and where to release a drug payload, and to self-destruct when the job is done.

The Harvard team's research was published in the journal Molecular Cell.