The nematode Caenorhabditis elegans is present in soils and composts, where it can encounter a variety of microorganisms. Some bacteria in these rich environments are innocuous food sources for C. elegans, whereas others are pathogens. Under laboratory conditions, C. elegans will avoid certain pathogens, such as Serratia marcescens, by exiting a bacterial lawn a few hours after entering it. By combining bacterial genetics and nematode genetics, we show that C. elegans specifically avoids certain strains of Serratia based on their production of the cyclic lipodepsipentapeptide serrawettin W2. Lawn-avoidance behavior is chiefly mediated by the two AWB chemosensory neurons, probably through G protein-coupled chemoreceptors, and also involves the nematode Toll-like receptor gene tol-1. Purified serrawettin W2, added to an Escherichia coli lawn, can directly elicit lawn avoidance in an AWB-dependent fashion, as can another chemical detected by AWB. These findings represent an insight into chemical recognition between these two soil organisms and reveal sensory mechanisms for pathogen recognition in C. elegans.behavior ͉ biosurfactants ͉ host-pathogen interactions ͉ nonribosomal peptide synthetase ͉ olfaction