The voices warning of the demise of our antibiotic defences are getting louder. With common pathogens such as E. coli and the pneumonia bug K. pneumoniae developing resistance to our antibiotics of last resort, leading pharmacologists, clinicians and epidemiologists say we risk being cast back to a time when even routine surgery put Victorians at risk of fatal infection.

It’s no mystery what the problem is. Complacent over-prescription of antibiotics by doctors, and their reckless, profligate use in livestock rearing, has provided ample opportunity for resistant strains of pathogenic bacteria to proliferate through natural selection. The solution is less obvious. An imminent and widespread outbreak of responsible antibiotic use seems unlikely. The financial incentive that usually drives private sector drug development is weakened by the knowledge that more profitable all-purpose antibiotics become obsolete more quickly because of the likely faster emergence of resistance.

Researchers in the Netherlands are exploring a novel way forward. What if antibiotics could be deactivated after use so that they no longer accumulate in the environment where they encourage the emergence of resistant bugs? A team at the University of Groningen has demonstrated a way to switch off antibiotic agents after just a few hours using warmth or sunlight.

The basic concept is to equip drug molecules with chemical components that change shape in response to heat or light. Many drugs work by sticking to and deactivating particular enzyme molecules in the body, disabling their function. Antibiotics typically work by disrupting functions that are essential to the survival of bacterial cells. And the way a drug binds to its target usually depends on it having a shape that fits rather precisely into a “slot” on the target enzyme. So if a drug changes shape, it might no longer work.

Light-switchable drugs have been explored in other fields such as cancer therapy, but not for antibiotics. Organic chemist Ben Feringa at Groningen and his co-workers used an existing light-switchable unit called azobenzene, which consists of two benzene molecules joined together by two nitrogen atoms linked by a double chemical bond. The double bond prevents the benzene group at each end from rotating around the "axle" linking them. They must remain either both on the same side of the molecule in a flattened C shape, or on opposite sides like a Z. These two different forms are called isomers: molecules with the same molecular formula but different structures and properties.

Crucially, heat and light can temporarily loosen up the bond between the nitrogen atoms, allowing them to rotate. If the Z-shaped isomer absorbs ultraviolet light, it will become switch to the C-shaped isomer. The reverse shape change can be induced by visible light or gentle heating at around body temperature.

Feringa and colleagues substituted the azobenzene switch for a similar chemical grouping within several variants of an antibacterial molecule called a quinolone, which tackle some types of bacteria by binding to an enzyme essential for replicating DNA. Several of these modified quinolones remained active against E. coli and other bacteria. Or at least they were after exposure to ultraviolet light made them switch to the C-isomer. Later, after being warmed inside the body or exposed to sunlight, they reverted to the Z-form, which is all but useless as an antibiotic.

Not only could this innovation prevent accumulation of active antibiotics in the environment, but it might also help to reduce side effects. One of these comes from their indiscriminate nature: when swallowed, they tend to attack the “friendly” bacteria in the gut as well as pathogens. Drugs equipped with activation switches could be administered orally and then turned on with light once they reach the part of the body (the throat or lungs, say) where the harmful bacteria are lurking.

Switching on drugs with ultraviolet light is not ideal in practice because it can have harmful effects. Feringa says he is now working on developing molecules than can be shape-shifted with visible light, or better still infrared, which can penetrate into the body without causing any harm.

If you would like to comment on this article or anything else you have seen on Future, head over to our Facebook page or message us on Twitter.