Each immune cell recognizes a specific part of a specific foreign protein. So, an immune cell that recognizes a protein from a specific virus is primed to attack that virus (and only that virus). Immune cells normally will not recognize "self" proteins made by the body. This prevents immune cells from attacking healthy cells (though sometimes this goes wrong in autoimmune diseases). Cancer, however, is caused by mutations to various proteins, and sometimes these mutant proteins can be recognized as non-self by immune cells. Immune cells that recognize these mutated cancer genes can help fight cancer and are the ones that are useful for immunotherapy.