Viruses are promising oncolytic agents in the treatment of cancer and gene delivery vectors for gene therapy and regenerative medicine, but there are safety concerns regarding their use, necessitating the development of fail-safe mechanisms that control viral replication. Tahara et al. report a photocontrollable system for the spatiotemporal regulation of mononegavirus gene expression and replication. Recombinant measles and rabies viruses were generated that express a photocontrollable L protein, the viral RNA polymerase. A ‘magnet system’ consisting of paired photoswitchable proteins (which heterodimerize upon blue light irradiation) was engineered into the flexible domains of the viral L proteins such that they would activate polymerase activity when they heterodimerize. These viruses could only replicate in the presence of blue light, and viral titres significantly reduced when blue light was removed. Mice bearing cancerous tumours were intratumourally treated with the photocontrollable measles virus and only mice treated under blue light survived.