The thymus trains immature T cells from the bone marrow to become mature cells that only attack foreign cells. In the thymus cortex, T cells encounter epithelial cells presenting various antigens. T cells that respond to foreign antigens are selected to survive and migrate to the medulla, while others undergo apoptosis. This is called positive selection.