The function of the immune system is to protect the body and destroy threats inside the body to prevent death; to elaborate upon that, the immune system is a defence force inside your body. You have scouts (Dendritic cells) that alert the body in the event of a breach of basic defence, you have guards (white blood cells) who will try to capture and capture pathogens before they can cause excessive damage, and should the pathogens infect cells, the big guns get called in: T cells. T cells are brutal, destroying infected cells to kill the pathogen and its antigens.