Encapsulated cell-based therapies involve the use of genetically-modified cells embedded in a material in order to produce a therapeutic agent in a specific location in the patient's body. This approach has shown great potential in animal model systems for treating diseases such as type I diabetes or cancer, with selected approaches having been tested in clinical trials. Despite the promise shown by encapsulated cell therapy, though, there are safety concerns yet to be addressed, such as the escape of the engineered cells from the encapsulation material and the resulting production of therapeutic agents at uncontrolled sites in the body. For that reason, there is great interest in the implementation of safety switches that protect from those side effects. Here, we develop a material-genetic interface as safety switch for engineered mammalian cells embedded into hydrogels. Our switch allows the therapeutic cells to sense whether they are embedded in the hydrogel by means of a synthetic receptor and signaling cascade that link transgene expression to the presence of an intact embedding material. The system design is highly modular, allowing its flexible adaptation to other cell types and embedding materials. This autonomously acting switch constitutes an advantage over previously described safety switches, which rely on user-triggered signals to modulate activity or survival of the implanted cells. We envision that the concept developed here will advance the safety of cell therapies and facilitate their translation to clinical evaluation.