They're recognized by the immune cells.
Pathogens have different distinguashable patterns in their molecules, which allows our immune cells to tell wether a body is pathogenic or not. Once these pathogenic bodies are recognized, then the whole immune system starts working to fight against the infection.
Hope it helped,
BioTeacher101