Synthetic microbial consortia represent a new frontier for synthetic biology given that they can solve more complex problems than monocultures. However, most attempts to co-cultivate these artificial communities fail because of the ‘‘winner-takes-all’’ in nutrients competition. In soil, multiple species can coexist with a spatial organization. Inspired by nature, here we show that an engineered spatial segregation method can assemble stable consortia with both flexibility and precision. We create microbial swarmbot consortia (MSBC) by encapsulating subpopulations with polymeric microcapsules. The crosslinked structure of microcapsules fences microbes, but allows the transport of small molecules and proteins. MSBC method enables the assembly of various synthetic communities and the precise control over the subpopulations. These capabilities can readily modulate the division of labor and communication. Our work integrates the synthetic biology and material science to offer new insights into consortia assembly and server as foundation to diverse applications from biomanufacturing to engineered photosynthesis.