Therapy Adapted for High Risk and Low Risk HIV-Associated Anal Cancer

This phase II trial studies the side effects of chemotherapy and intensity modulated radiation therapy in treating patients with low-risk HIV-associated anal cancer, and nivolumab after standard of care chemotherapy and radiation therapy in treating patients with high-risk HIV-associated anal cancer. Radiation therapy uses high energy x-rays to kill tumor cells and shrink tumors. Chemotherapy drugs, such as mitomycin, fluorouracil, and capecitabine, work in different ways to stop the growth of tumor cells, either by killing the cells, by stopping them from dividing, or by stopping them from spreading. Giving chemotherapy with radiation therapy may kill more tumor cells. Immunotherapy with monoclonal antibodies, such as nivolumab, may help the body's immune system attack the cancer, and may interfere with the ability of tumor cells to grow and spread. Giving nivolumab after standard of care chemotherapy and radiation therapy may help reduce the risk of the tumor coming back.

PRIMARY OBJECTIVES:

I. To determine the safety of reduced intensity chemo-radiation therapy (CRT) in low-risk disease.

II. To determine the safety of nivolumab after standard CRT in high-risk disease.

SECONDARY OBJECTIVES:

I. To estimate the efficacy (2-year disease-control rate \[DCR\]) of reduced intensity CRT in low risk disease.

II. To estimate the efficacy (2-year disease-free survival \[DFS\] rate) of nivolumab after standard CRT in high risk disease.

III. To evaluate the effect of low-dose CRT on immune function (CD4+ cell count) and human immunodeficiency virus (HIV) viral load.

IV. To evaluate the effect of nivolumab on immune function (CD4+ cell count) and HIV viral load.

V. To assess combination antiretroviral therapy (cART) adherence before, during, and after treatment with CRT and nivolumab to identify potential barriers to cART adherence when receiving concurrent oncological care.

EXPLORATORY OBJECTIVES:

I. To determine the human papillomavirus (HPV) genotype in primary tumor and explore the relationship between specific HPV subtypes and clinical response to reduced intensity CRT or nivolumab.

II. To explore the relationship between expression of PD-1 in immune cells and PD-L1 in immune cells or cancer epithelial cells in the primary diagnostic tumor and clinical response to nivolumab or reduced intensity CRT.

III. To describe the effects of reduced intensity CRT and nivolumab on viral HIV reservoirs.

IV. To identify the presence of cell-free plasma HPV deoxyribonucleic acid (DNA) before and after reduced intensity CRT and nivolumab and explore the relationship with clinical response.

V. To describe the effect of reduced intensity CRT on quality of life (QOL).

OUTLINE: Patients are assigned to 1 of 2 stratum.

HIGH-RISK STRATUM: Patients receive nivolumab intravenously (IV) over 30 minutes on day 1. Treatment repeats every 4 weeks for up to 6 cycles in the absence of disease progression or unacceptable toxicity. Patients also undergo echocardiography (ECHO) during screening as clinically indicated, sigmoidoscopy/colonoscopy, anoscopy/proctoscopy or digital rectal exam and computed tomography (CT) throughout the study as well as blood sample collection during screening and end of treatment (EOT).

LOW-RISK STRATUM: Patients receive mitomycin IV on day 1 and either fluorouracil IV on day 1 or capecitabine orally (PO) twice daily (BID) on Monday-Friday until the completion of radiation therapy at the discretion of the treating physician. Patients also undergo intensity modulated radiation therapy (IMRT) once daily (QD) for 20-23 treatment sessions over 6 weeks. Patients also undergo digital rectal exam, anoscopy/proctoscopy and CT throughout the study, receive fludeoxyglucose F-18 (FDG) IV and undergo positron emission tomography (PET)/CT, PET/magnetic resonance imaging (MRI) and /or MRI during screening and follow-up as well as blood sample collection during screening and EOT. Some patients undergo lymph node biopsy during screening at the discretion of the treating physician.

After completion of study treatment, patients are followed up at 6 weeks, every 3 months for years 1-2, every 6 months for year 3, and then annually for years 4-5.

Eligibility Criteria:
Inclusion Criteria:

* HIGH-RISK STRATUM: Participant is able to understand and willing to sign a written informed consent document
* HIGH-RISK STRATUM: Participant must have histologically proven stage (T3-T4N0M0 OR T2-4N1M0) invasive squamous cell carcinoma (SCC) of the anus or anorectum as documented before CRT initiation, according to the American Joint Committee on Cancer (AJCC) 8th edition. Participants with squamous cell carcinoma of the anal margin are eligible if there is evidence of extension of the primary tumor into the anal canal. Participants with tumors of non-keratinizing histology such as basaloid, transitional cell or cloacogenic histology are permitted
* HIGH-RISK STRATUM: HIV-positive. Documentation of HIV-1 infection by means of any one of the following:

  * Documentation of HIV diagnosis in the medical record by a licensed health care provider. If the record contains information that the patient is taking Food and Drug Administration (FDA)-approved combination therapy for HIV infection, then this can be part of the record substantiating the HIV positive diagnosis
  * HIV-1 ribonucleic acid (RNA) detection by a licensed HIV-1 RNA assay demonstrating \> 1000 RNA copies/mL
  * Any licensed HIV screening antibody and/or HIV antibody/antigen combination assay confirmed by a second licensed HIV assay such as a HIV-1 Western blot confirmation or HIV rapid multispot antibody differentiation assay.

    * NOTE: The term "licensed" refers to a kit that has been certified or licensed by an oversight body within the participating country and validated internally (e.g., United States \[U.S.\] FDA)
    * WHO (World Health Organization) and CDC (Centers for Disease Control and Prevention) guidelines mandate that confirmation of the initial test result must use a test that is different from the one used for the initial assessment. A reactive initial rapid test must be confirmed by either another type of rapid assay or an E/CIA that is based on a different antigen preparation and/or different test principle (e.g., indirect versus competitive), or a Western blot or a plasma HIV-1 RNA viral load
* HIGH-RISK STRATUM: Age \>= 18 years

  * Because no dosing or adverse event data are currently available on the use of nivolumab in participants \< 18 years of age, children are excluded from this study
* HIGH-RISK STRATUM: Eastern Cooperative Oncology Group (ECOG) performance status =\< 2 (Karnofsky \>= 50%)
* HIGH-RISK STRATUM: Life expectancy of greater than 6 months
* HIGH-RISK STRATUM: Hemoglobin \> 10 g/dL (within 2 weeks before enrollment)
* HIGH-RISK STRATUM: Absolute neutrophil count: \>= 1,500/mm\^3 (within 2 weeks before enrollment)
* HIGH-RISK STRATUM: Platelets: \>= 100,000/mm\^3 (within 2 weeks before enrollment)
* HIGH-RISK STRATUM: Total bilirubin: \< 2 X upper limit of normal (ULN) (within 2 weeks before enrollment)
* HIGH-RISK STRATUM: Aspartate aminotransferase (AST) (serum glutamic oxaloacetic transaminase \[SGOT\]) / alanine aminotransferase (ALT) (serum glutamic pyruvic transaminase \[SGPT\]): =\< 2.5 X institutional ULN (within 2 weeks before enrollment)
* HIGH-RISK STRATUM: Albumin \>= 3.0 g/dL (within 2 weeks before enrollment)
* HIGH-RISK STRATUM: Creatinine levels =\< 1.5 X normal institutional limits; or calculated creatinine clearance must be \> 50 ml/min (within 2 weeks before enrollment)
* HIGH-RISK STRATUM: Females of childbearing potential (FOCBP) must agree to follow contraception requirements:

  * The effects of nivolumab on the developing human fetus are unknown. For this reason and because other therapeutic agents used in this trial are known to be teratogenic, FOCBP must agree to use adequate contraception (hormonal or barrier method of birth control; abstinence) before study entry, for the duration of study participation and 5 months after completion of nivolumab administration. Should a woman become pregnant or suspect she is pregnant while she is participating in this study, she should inform her treating physician immediately

    * NOTE: A female of childbearing potential is any woman, regardless of sexual orientation or whether they have undergone tubal ligation, who meets the following criteria: 1) has achieved menarche at some point, 2) has not undergone a hysterectomy or bilateral oophorectomy; or 2) has not been naturally postmenopausal (amenorrhea following cancer therapy does not rule out childbearing potential) for at least 24 consecutive months (i.e., has had menses at any time in the preceding 24 consecutive months)
* HIGH-RISK STRATUM: Participant must have a CD4 count of \>= 100 cells/uL at least 2 weeks prior to enrollment OR \>= 100 cells/uL before receiving prior CRT, as CD4 may be low due to the effects of CRT
* HIGH-RISK STRATUM: Participant must be on a stable antiretroviral therapy (ART) regimen for at least 2 weeks prior to enrollment with no intention to change the regimen within 12 weeks after enrollment
* HIGH-RISK STRATUM: Participant must have an HIV RNA viral load of \< 200 copies/mL
* HIGH-RISK STRATUM: Participant must have received at least 54 Gy of radiation to the PTVp (primary) and 45 Gy to PTVn (elective nodal region) for the treatment of the anal cancer within 9 weeks before enrollment
* HIGH-RISK STRATUM: Participant must have =\< grade 2 diarrhea

  * Participants with grade 1 or grade 2 diarrhea are eligible provided stool for ova/parasites and stool cryptosporidium studies are negative
* HIGH-RISK STRATUM: Purified protein derivative (PPD) negative. Alternatively, the QuantiFERON-tuberculosis (TB) Gold In-Tube (QFT-GIT) assay (Cellestis Limited, Carnegie, Australia) can be used. An individual is considered positive for M. tuberculosis infection if the interferon (IFN)-gamma response to TB antigens is above the test cut-off (after subtracting the background IFN-gamma response in the negative control). The result must be obtained within 20 weeks prior to enrollment. PPD positive (or QuantiFERON assay positive) participants are permitted if prophylaxis has been completed prior to enrollment
* HIGH-RISK STRATUM: Participants with impaired decision-making capacity (IDMC) may be eligible for the study provided all other eligibility criteria are satisfied:

  * The participant's legally authorized representative (LAR) is able and willing to sign consent in addition to the study candidate
  * Both participant and LAR agree to follow study parameters per protocol
* HIGH-RISK STRATUM: The participant, in the opinion of the treating investigator, is able to receive IV contrast injections:

  * All participants in the High-risk Stratum must have an oral contrast (rectal contrast optional) and IV iodine contrast abdomen and pelvis contrast CT (A/P C+CT) and chest C+CT at baseline and for all clinical follow up time points. Imaging centers should follow their local routine guidelines for determination of patient eligibility for IV contrast injection and appropriate post contrast follow up renal function determinations
* SCREENING ELIGIBILITY LOW-RISK STRATUM: Participant is able to understand and willing to sign a written informed consent document
* SCREENING ELIGIBILITY LOW-RISK STRATUM: Age \>= 18 years

  * Because no dosing or adverse event data are currently available on the use of low-dose radiation concurrent with mitomycin-C/fluorouracil (5-FU) or mitomycin-C/capecitabine in participants \< 18 years of age, children are excluded from this study
* SCREENING ELIGIBILITY LOW-RISK STRATUM: Participant must have histologically proven T1-2N0M0 invasive anal canal or anal margin squamous cell carcinoma with tumors measuring =\< 4 cm within 6 weeks before pre-registration. Measurable disease is not required. Participants with tumors of non-keratinizing histology such as basaloid, transitional cell, or cloacogenic histology are permitted. Participants who are status/post local excision or excisional biopsy procedure are eligible provided there was tumor involvement of the anal canal and/or anal verge prior to the reaction, if the margins were positive, and/or if the stage is T2N0 based on tumor size before the procedure. This means that participants with T1N0M0 anal margin squamous cell carcinoma who underwent surgical excision with negative margins and no involvement of the anal verge and/or anal canal are not eligible Baseline imaging including, FDG-PET/CT and A/P C+CT must be submitted for central review for confirmation of no lymph node involvement. Results of central review (including discrepancies between local read and central review) will be returned to the site within 5 business days of submission, allowing participants with imaging suspicious for lymph node (LN) involvement determined by central review to undergo a fine needle aspirate (FNA) or core biopsy at their local center confirming no lymph node involvement (N0) for eligibility
* SCREENING ELIGIBILITY LOW-RISK STRATUM: HIV positive. Documentation of HIV-1 infection by means of any one of the following:

  * Documentation of HIV diagnosis in the medical record by a licensed health care provider. If the record contains information that the patient is taking FDA-approved combination therapy for HIV infection, then this can be part of the record substantiating the HIV positive diagnosis
  * HIV-1 RNA detection by a licensed HIV-1 RNA assay demonstrating \> 1000 RNA copies/mL
  * Any licensed HIV screening antibody and/or HIV antibody/antigen combination assay confirmed by a second licensed HIV assay such as a HIV-1 Western blot confirmation or HIV rapid multispot antibody differentiation assay.

    * NOTE: The term "licensed" refers to a kit that has been certified or licensed by an oversight body within the participating country and validated internally (e.g., U.S. FDA)
    * WHO (World Health Organization) and CDC (Centers for Disease Control and Prevention) guidelines mandate that confirmation of the initial test result must use a test that is different from the one used for the initial assessment. A reactive initial rapid test must be confirmed by either another type of rapid assay or an E/CIA that is based on a different antigen preparation and/or different test principle (e.g., indirect versus competitive), or a Western blot or a plasma HIV-1 RNA viral load
* SCREENING ELIGIBILITY LOW-RISK STRATUM: Tumor size must be documented by digital rectal exam and anoscopy/proctoscopy within 6 weeks prior to pre-registration
* SCREENING ELIGIBILITY LOW-RISK STRATUM: Life expectancy of greater than 6 months
* LOW-RISK STRATUM: Participant satisfies all criteria in Eligibility for Screening Low-Risk Stratum. Participants with imaging suspicious for LN involvement determined by central review must undergo a fine needle aspirate (FNA) or core biopsy confirming no lymph node involvement (N0)
* LOW-RISK STRATUM: ECOG performance status =\< 2 (Karnofsky \>= 50%)
* LOW-RISK STRATUM: Hemoglobin \> 10 g/dL (within 2 weeks before enrollment)
* LOW-RISK STRATUM: Absolute neutrophil count: \>= 1,500/mm\^3 (within 2 weeks before enrollment)
* LOW-RISK STRATUM: Platelets: \>= 100,000/mm\^3 (within 2 weeks before enrollment)
* LOW-RISK STRATUM: Total bilirubin: \< 2 X ULN (within 2 weeks before enrollment)
* LOW-RISK STRATUM: AST (SGOT) / ALT (SGPT): =\< 2.5 X institutional ULN (within 2 weeks before enrollment)
* LOW-RISK STRATUM: Albumin \>= 3.0 g/dL (within 2 weeks before enrollment)
* LOW-RISK STRATUM: Serum creatinine levels =\< 1.5 X ULN or calculated creatinine clearance must be \> 50 ml/min (within 2 weeks before enrollment)
* LOW-RISK STRATUM: Participant must agree to follow contraception requirements:

  * Females of childbearing potential (FOCBP) and sexually active males must be strongly advised to use accepted and effective method(s) of contraception or to abstain from sexual intercourse for the duration of their participation in the study and for at least 6 months after the completion of treatment
  * NOTE: FOCBP is defined as a sexually mature woman, regardless of sexual orientation or whether they have undergone tubal ligation who: 1) has not undergone a hysterectomy or bilateral oophorectomy; or 2) has not been naturally postmenopausal for at least 24 consecutive months, i.e., has had menses at any time in the preceding 24 consecutive months
* LOW-RISK STRATUM: Participant must have a CD4 count of \>= 100 cells/uL at least 2 weeks before enrollment
* LOW-RISK STRATUM: Participant must on a stable ART regimen for at least 2 weeks before enrollment and receive appropriate care and treatment for HIV infection under the care of a physician experienced in HIV management
* LOW-RISK STRATUM: Participant has a HIV RNA viral load of \< 200 copies/mL
* LOW-RISK STRATUM: Participant has started an alternative anti-coagulant regimen within 2 weeks prior to enrollment if taking warfarin and considering capecitabine

  * NOTE: Low molecular weight heparin is permitted provided the participants prothrombin time (PT)/international normalized ratio (INR) is \< 1.5
* LOW-RISK STRATUM: Participant must agree to having phenytoin levels checked weekly if planning to receive capecitabine while taking phenytoin for a seizure disorder
* LOW-RISK STRATUM: Participants with IDMC may be eligible for the study provided all other eligibility criteria are satisfied:

  * The participant's legally authorized representative (LAR) is able and willing to sign consent in addition to the study candidate
  * Both participant and LAR agree to follow study parameters
* LOW-RISK STRATUM: The participant, in the opinion of the treating investigator, is able to receive IV contrast injections:

All participants in the Low-risk Stratum must have an oral contrast (rectal contrast optional) and IV iodine contrast CT (A/P C+CT and chest C+CT) at baseline and for all clinical follow up time points. Imaging centers should follow their local routine guidelines for determination of patient eligibility for IV contrast injection and appropriate post contrast follow up renal function determinations

Exclusion Criteria:

* HIGH-RISK STRATUM: Any live vaccines within 30 days prior to enrollment

  * Examples of live vaccines include, but are not limited to, the following: measles, mumps, rubella, chicken pox, yellow fever, rabies, Bacillus Calmette-Guerin (BCG), and typhoid (oral) vaccine. Seasonal influenza vaccines for injection are generally killed virus vaccines and are allowed; however, intranasal influenza vaccines (e.g., Flu-Mist) are live attenuated vaccines and are not allowed
  * NOTE: No live vaccines may be administered while participating in the trial.
* HIGH-RISK STRATUM: Participant has known interstitial lung disease that is symptomatic or may interfere with the detection or management of suspected drug-related pulmonary toxicity
* HIGH-RISK STRATUM: Prior treatment with an immune checkpoint inhibitor (anti-PD-1, anti-PD-L1, anti-PD-L2, anti-CTLA4 monoclonal antibody)
* HIGH-RISK STRATUM: Participant with an allogenic bone marrow/stem, cell or solid organ transplant
* HIGH-RISK STRATUM: Participant is receiving any other investigational agents
* HIGH-RISK STRATUM: History of allergic reactions attributed to compounds of similar chemical or biologic composition to nivolumab or other agents used in study
* HIGH-RISK STRATUM: Uncontrolled intercurrent illness including, but not limited to, ongoing or active infection, symptomatic congestive heart failure, unstable angina pectoris, cardiac arrhythmia or psychiatric illness/social situations that would limit compliance with study requirements
* HIGH-RISK STRATUM: Participant has a history of a different malignancy, unless he/she have been disease-free for at least 2 years and are deemed by the investigator to be at low risk of recurrence

  * NOTE: Individuals with the following cancers are eligible if diagnosed and treated within the past 5 years: cervical cancer in situ, basal cell or squamous cell carcinoma of the skin, and stage I and IIA/IIB resected melanoma. In addition, participants on hormonal treatment for breast/gynecological and prostate tumors with no evidence of active disease are permitted, as well as participants with controlled Kaposi sarcoma (KS) not requiring systemic KS directed therapy
* HIGH-RISK STRATUM: Pregnant or breastfeeding.

  * Pregnant women are excluded from this study because nivolumab is an anti-PD-1MAb agent with the potential for teratogenic or abortifacient effects. Because there is an unknown but potential risk for adverse events in nursing infants secondary to treatment of the mother with nivolumab, breastfeeding should be discontinued if the mother is treated with nivolumab
  * All FOCBP must have a blood test or urine study within 2 weeks prior to enrollment to rule out pregnancy
* HIGH-RISK STRATUM: Participant has not recovered from adverse events due to CRT (i.e., have residual toxicity \> grade 1), excluding alopecia
* HIGH-RISK STRATUM: Participant has had prior potentially curative surgery (i.e., abdominal-perineal resection) for carcinoma of the anus
* HIGH-RISK STRATUM: Participant is receiving other standard anti-cancer therapy or experimental agent concurrently with the study drugs
* HIGH-RISK STRATUM: Participant has a known autoimmune disease

  * Participants with active autoimmune disease or history of autoimmune disease that might recur, which may affect vital organ function or require immune suppressive treatment including systemic corticosteroids, should be excluded. These include but are not limited to participants with a history of immune related neurologic disease, multiple sclerosis, autoimmune (demyelinating) neuropathy, Guillain-Barre syndrome, myasthenia gravis; systemic autoimmune disease such as systemic lupus erythematosus (SLE), connective tissue diseases, scleroderma, inflammatory bowel disease (IBD), Crohn's, ulcerative colitis, hepatitis; and participants with a history of toxic epidermal necrolysis (TEN), Stevens-Johnson syndrome, or phospholipid syndrome should be excluded because of the risk of recurrence or exacerbation of disease. Participants with vitiligo, endocrine deficiencies including thyroiditis managed with replacement hormones including physiologic corticosteroids are eligible. Participants with rheumatoid arthritis and other arthropathies, Sjogren's syndrome and psoriasis controlled with topical medication and participants with positive serology, such as antinuclear antibodies (ANA), anti-thyroid antibodies should be evaluated for the presence of target organ involvement and potential need for systemic treatment but should otherwise be eligible
* HIGH-RISK STRATUM: Participant requires steroid treatment or other immunosuppressive treatment

  * Participants will be excluded if they have a condition requiring systemic treatment with either corticosteroids (\> 10 mg daily prednisone equivalents) or other immunosuppressive medications within 7 days of study drug administration. Topical corticosteroid or occasional inhaled corticosteroids are allowed
* HIGH-RISK STRATUM: Any surgery must have been completed \>= 4 weeks before treatment initiation
* LOW-RISK STRATUM: Has undergone prior potentially curative surgery (i.e., abdominal-perineal resection) for carcinoma of the anus
* LOW-RISK STRATUM: Receiving any other standard anti-cancer therapy or investigational agents concurrently with study therapy
* LOW-RISK STRATUM: Significant cardiovascular disease including myocardial infarction, unstable angina, stroke, transient ischemic attack, symptomatic coronary artery disease, symptomatic congestive heart failure, or uncontrolled cardiac arrhythmia within 6 months of enrollment
* LOW-RISK STRATUM: History of prior chemotherapy for this malignancy
* LOW-RISK STRATUM: Pregnant and/or breast-feeding women

  * Pregnant and/or breast-feeding women are excluded from this study because the study treatment administered