In vertebrates, interaction between the nervous system and immune system is important to protect a challenged host from stress inputs from external sources. In this study, we demonstrate that sensory neurons are involved in the cellular immune response elicited by wasp infestation of Drosophila larvae. Multidendritic class IV neurons sense contacts from external stimuli and induce avoidance behaviors for host defense. Our findings show that inactivation of these sensory neurons impairs the cellular response against wasp parasitization. We also demonstrate that the nociception genes encoding the mechanosensory receptors Painless and Piezo, both expressed in class IV neurons, are essential for the normal cellular immune response to parasite challenge.