Background Children who are stunted (length-for-age Z-score<-2) are at greater risk of infectious morbidity and mortality. Previous studies suggest that stunted children have elevated inflammatory biomarkers, but no studies have characterised their capacity to respond to new infections (i.e., their immune function). We hypothesised that antibacterial immune function would differ between stunted and non-stunted children and relate to their health and environment during early life. Methods We enrolled a cross-sectional cohort of 113 HIV-negative children nested within a longitudinal cluster-randomised controlled trial of household-level infant and young child feeding (IYCF) and water, sanitation and hygiene (WASH) interventions in rural Zimbabwe (SHINE; Clinical trials registration: NCT01824940). Venous blood was collected at 18 months of age and cultured for 24 h without antigen or with bacterial antigens: heat-killed Salmonella typhimurium (HKST) or Escherichia coli lipopolysaccharide (LPS). TNFα, IL-6, IL-8, IL-12p70, hepcidin, soluble (s)CD163, myeloperoxidase (MPO) and IFNβ were quantified in culture supernatants by ELISA to determine antigen-specific immune function. The effect of stunting status and early-life exposures (anthropometry, inflammation at 18 months, maternal health during pregnancy, household WASH) on immune function was tested in logit and censored log-normal (tobit) regression models. Results Children who were stunted (n = 44) had higher proportions (86.4% vs. 65.2%; 88.6% vs. 73.4%) and concentrations of LPS-specific IL-6 (geometric mean difference (95% CI): 3.46 pg/mL (1.09, 10.80), p = 0.035) and IL-8 (3.52 pg/mL (1.20, 10.38), p = 0.022) than non-stunted children (n = 69). Bacterial antigen-specific pro-inflammatory cytokine concentrations were associated with biomarkers of child enteropathy at 18 months and biomarkers of systemic inflammation and enteropathy in their mothers during pregnancy. Children exposed to the WASH intervention (n = 33) produced higher LPS- (GMD (95% CI): 10.48 pg/mL (1.84, 60.31), p = 0.008) and HKST-specific MPO (5.10 pg/mL (1.77, 14.88), p = 0.003) than children in the no WASH group (n = 80). There was no difference in antigen-specific immune function between the IYCF (n = 55) and no IYCF groups (n = 58). Conclusions Antibacterial immune function among 18-month-old children in a low-income setting was shaped by their stunting status and prior exposure to maternal inflammation and household WASH. Heterogeneity in immune function due to adverse exposures in early life could plausibly contribute to infection susceptibility.