Swarms of microscale robots are controlled by external magnetic fields to collectively capture microplastics and bacteria present in aquatic systems.