The composition of intrinsic microbial communities determines if invading pathogens will find a suitable niche for colonization and cause infection or be eliminated. Here, we investigate how commensal E. coli mediate colonization resistance (CR) against Salmonella Typhimurium (S. Tm). Using synthetic bacterial communities, we show that the capacity of E. coli Mt1B1 to block S. Tm colonization depends on the microbial context. In an infection-permissive context, E. coli utilized a high diversity of carbon sources and was unable to block S. Tm invasion. In mice that were stably colonized by twelve phylogenetically diverse murine gut bacteria (OMM12), establishing a protective context, E. coli depleted galactitol, a substrate otherwise fueling S. Tm colonization. Here, Lachnospiraceae, capable of consuming C5 and C6 sugars, critically contributed to CR. We propose that E. coli provides CR by depleting a limited carbon source when in a microbial community adept at removing simple sugars from the intestine.