Scientists have developed a technique that could be used to deliver precise doses of hormones to people who don't make them naturally.
To do this, they rewired kidney cells with light-sensitive molecules from the eye, they reported in the journal Science.
When pulsed with blue light, these cells churned out proteins on demand.
Ultimately, this technique could avoid the need for people with diabetes to inject themselves regularly.
"When I speak to diabetes patients they say that if you could take away always having to inject themselves it would really increase their quality of life," said lead author Martin Fussenegger, a bioengineer of the Swiss Federal Institute of Technology, Zurich.
Dr Fussenegger thought he saw a solution in his own field of optogenetics. Optogenetics, as the name suggests, uses light to control the behaviour cells.
To get a cell to respond to light you first have to rejigger it so it has a light-sensitive molecule on its surface. Dr Fussenegger coaxed kidney cells to express melanopsin, a molecule usually found in animals' eyes.
He then placed these cells into diabetic mice. Along with the cells he placed an optic fibre, down which he could pulse blue light to expose the cells at his command.
In the dark, these cells behaved as usual; In the light, however, genes in the cell were switched on and the cell pumped out a protein required for the breakdown of sugars in the blood, helping the mice to control their glucose levels.
He hopes that cells like these could ultimately be implanted into people, and exposed to light - either through the skin or down a optic fibre - to release proteins that would help treat diabetes.
The new technique is a proof of principle. He told BBC News that it was not limited to treating diabetes; this technology could be usedto switch on genes to produce many different proteins in people who do not make them naturally, or are not making enough of them to be healthy.
"I think this is a phenomenal research tool," said James Collins, a synthetic biologist at Howard Hughes Medical Institute, Maryland, US, who was not involved in the work.
Dr Collins explained that as we move into an age of regenerative medicine, and begin to think of how we use stem cells to produce different tissues in the body, one of the challenges will be to work out which genes are needed to produce certain tissues and cells.
This new technique allows researchers to switch genes on and off to determine which are essential to make a specific tissues.