Cancer vaccines work by introducing antigens related to specific types of cancer into the body. These antigens prompt the immune system to recognize and attack cancer cells that express these antigens. The vaccines can be prophylactic, aiming to prevent cancer, or therapeutic, for treating existing cancer.