When compared to microorganisms, we evolve at a glacial pace - in just an hour and a half, E. coli effortlessly ticks through as many generations we've accrued since the beginning of civilisation! The major implication of this, for our own immune system, is that we can't possibly be genetically programmed with a "hit list" of foreign antigens for us to attack. Pathological microorganisms simply evolve too quickly - they'd be rapidly evolving new antigens far more quickly than we could evolve an updated hit list.
In terms of the adaptive immune system, therefore, what our bodies do is to prepare our immune cells with receptors for an unbelievably large repertoire of antigens, so that pretty much all microorganisms are covered. Should a different antigen evolve, the chances are that our body will be able to recognise it, and thus the microorganisms' advantage of rapid evolution is partly removed.
Solving one problem only brings another, however. Since the body is simply blindly generating random receptors for any possible antigen, what's to stop it incidentally generating receptors for its own tissues? In a word: nothing. In fact, since the body can generate receptors to almost an infinite number of antigens, the odds of there being no receptors targeting your own cells are vanishingly distant. How does the body avoid autoimmune diseases then, in the vast majority of cases?
A full answer to this question would exceed the usual length of my blog posts by about 100 times, so I thought I'd concentrate on one of the main mechanisms for immunological tolerance: the thymic selection process for T lymphocytes.
Although all lymphocytes begin their development in the bone marrow (in adults, anyway), T lymphocytes must complete this process in the thymus. (Technically, the cells should be called thymocytes until their full maturation, and so that's what we'll call them from here on.) The thymocytes gradually move from the (outer) subcapsular region through the cortex and into the (inner) medulla, and in doing so pass through several developmental stages. From our point of view, the first point of interest comes with their interaction with epithelial cells in the thymus' cortex.
At this point, the thymocytes have to interact with the MHC I molecules of the epithelial cells. As you may recall, the MHC molecules are the major immunological gate keepers of the adaptive immune system. On the whole, antigens simply can't be recognised by lymphocytes unless they are presented in conjunction with one of the MHC structures. (The innate immune system is usually able to function reasonably well necessarily without bothering about MHC molecules, however.) Lymphocytes that don't interact well enough with the MHC complexes of the thymic cortical epithelial cells are therefore useless to the body, immunologically, and so are consigned to the flames; apoptosis is induced in these thymocytes, and they are phagocytosed by resident macrophages. This whole process is called positive selection, since only cells that display enough reactivity are allowed to develop further.
Further towards the centre of the thymus (at the corticomedullary junction, as it turns out), the remaining thymocyte hopefuls must pass a second test: are they dangerous to the body? The thymocytes are exposed to autoantigens (antigens from the body) presented by the interdigitating cells and macrophages there, but this time the challenge has been reversed. Any cells reacting to the body's own antigens are now destroyed, in the same manner as above. Therefore, the remaining thymocytes, soon to become the body's pool of T lymphocytes, are theoretically only reactive to non-self antigens.
This negative selection neatly solves the problem, raised at the outset, of how to prevent T lymphocytes from attacking our own tissues. Something similar also happens in the bone marrow with regards to the B lymphocytes.