Natural populations often show genetic variation in pathogen resistance, which is paradoxal because natural selection is expected to erode genetic variation in fitness-related traits. Several different factors have been suggested to maintain such variation, but their relative importance is still poorly understood. Here we examined if environmental heterogeneity and genetic trade-offs could contribute to the maintenance of genetic variation in immune function of a freshwater snail Lymnaea stagnalis. We assessed the immunocompetence of snails originating from different families and maintained in different feeding treatments (ad libitum feeding, no food) by measuring the density of circulating hemocytes, phenoloxidase activity, and antibacterial activity of snail hemolymph. Food limitation reduced snail immune function, and we found significant among-family variation in hemocyte concentration and PO activity, but not in antibacterial activity. Interestingly, food availability modified the family-level variation observed in PO activity so that the relative immunocompetence of different snail families changed over environmental conditions (G × E interaction). We found no evidence for genetic trade-offs between snail growth and immune defense nor among immune traits. Thus, our findings support the idea that environmental heterogeneity may promote maintenance of genetic variation in immune defense, but also suggest that different immune traits might not respond similarly to environmental variation.