Caenorhabditis elegans exhibits avoidance behavior when presented with diverse bacterial pathogens. We hypothesized that exposure to pathogens might not only cause worms to move away but also simultaneously activate pathways that promote resistance to the pathogen. We show that brief exposure to virulent or avirulent strains of the bacterial pathogen enteropathogenic E. coli (EPEC) "immunizes"C. elegans to survive a subsequent exposure that would otherwise prove lethal, a phenomenon we refer to as "conditioning." Conditioning requires dopaminergic neurons; the p38 MAP kinase pathway, which regulates innate immunity; and the insulin/IGFR pathway, which regulates lifespan. Our findings suggest that the molecular pathways that control innate immunity and lifespan may be regulated or "conditioned" by exposure to pathogens to allow survival in noxious environments.