Bacteria can sense their environment, distinguish between cell types, and deliver proteins to eukaryotic cells. Here, we engineer the interaction between bacteria and cancer cells to depend on heterologous environmental signals. We have characterized invasin from Yersinia pseudotuburculosis as an output module that enables Escherichia coli to invade cancer-derived cells, including HeLa, HepG2, and U2OS lines. To environmentally restrict invasion, we placed this module under the control of heterologous sensors. With the Vibrio fischeri lux quorum sensing circuit, the hypoxia-responsive fdhF promoter, or the arabinose-inducible araBAD promoter, the bacteria invade cells at densities greater than 10(8)bacteria/ml, after growth in an anaerobic growth chamber or in the presence of 0.02% arabinose, respectively. In the process, we developed a technique to tune the linkage between a sensor and output gene using ribosome binding site libraries and genetic selection. This approach could be used to engineer bacteria to sense the microenvironment of a tumor and respond by invading cancerous cells and releasing a cytotoxic agent.