The following criteria is provided for health care professionals.
Inclusion Criteria:
* Documented informed consent of the patient and/or legally authorized representative (done within 30 days of HCT day 0).
* Agreement to allow the use of archival tissue from diagnostic tumor biopsies.
* If unavailable, exceptions may be granted with study principal investigator (PI) approval.
* Age: 18-75 years old.
* Eastern Cooperative Oncology Group =\< 2.
* Patients who are scheduled to undergo allogeneic HCT for AML with high-risk cytogenetics per European Leukemia Net (ELN) or MDS with International Prognostic Scoring System (IPSS) of intermediate 2 with poor risk cytogenetics or molecular markers. OR patients with MRD+ disease OR active disease with \< 10% blast at the time of HCT.
* Patients who are scheduled to undergo their first or second HCT with reduced intensity conditioning regimen (any reduced intensity conditioning regimen per institutional standards is allowed), and regardless of GVHD prophylactic regimen.
* Allogeneic transplant regardless of donor type (matched, mismatched, haploidentical, etc.) or graft source (bone marrow or mobilized peripheral blood stem cells) are included.
* Pre-HCT exposure to anti-CD47 of hypomethylating agent (HMA) is allowed if no progression on therapy has been documented.
* Absolute neutrophil count (ANC) \>= 1.5 (without the use of granulocyte-colony stimulating factor \[GCSF\] for last 2 weeks) (To be performed within 45 days prior to transplant unless otherwise stated).
* NOTE: Transfusion (Red blood cells \[RBC\] or platelet) to achieve the above-mentioned counts is allowed.
* Platelet count \>= 50K (To be performed within 45 days prior to transplant unless otherwise stated).
* NOTE: Transfusion (RBC or platelet) to achieve the above-mentioned counts is allowed.
* NOTE: Complete blood count (CBC) should be done within 2 weeks of day 1 of the protocol.
* Total bilirubin =\< 1.5 X upper limit of normal (ULN) (unless has Gilbert's disease) (To be performed within 45 days prior to transplant unless otherwise stated).
* Aspartate transaminase (AST) =\< 1.5X ULN (To be performed within 45 days prior to transplant unless otherwise stated).
* Alanine transaminase (ALT) =\< 1.5 X ULN (To be performed within 45 days prior to transplant unless otherwise stated).
* Creatinine clearance of \>= 60 mL/min per 24-hour urine test or the Cockcroft-Gault formula (To be performed within 45 days prior to transplant unless otherwise stated).
* Left ventricular ejection fraction (LVEF) \>= 45% (To be performed within 45 days prior to transplant unless otherwise stated).
* If able to perform pulmonary function tests: forced expiratory volume in 1 second (FEV1), forced vital capacity (FVC) and diffusing capacity of the lung for carbon monoxide (DLCO) (diffusion capacity) \>= 50% of predicted (corrected for hemoglobin). If unable to perform pulmonary function tests: oxygen (O2) saturation \> 92% on room air. (To be performed within 45 days prior to transplant unless otherwise stated).
* Women of childbearing potential (WOCBP): negative urine or serum pregnancy test. If the urine test is positive or cannot be confirmed as negative, a serum pregnancy test will be required. (To be performed within 45 days prior to transplant unless otherwise stated).
* Agreement by females and males of childbearing potential to use an effective method of birth control or abstain from heterosexual activity for the course of the study through at least 6 months after the last dose of protocol therapy.
* Childbearing potential defined as not being surgically sterilized (men and women) or have not been free from menses for \> 1 year (women only).
Exclusion Criteria:
* Patient who underwent more than 2 allogeneic HCTs.
* History of allergic reactions attributed to compounds of similar chemical or biologic composition to study agents (azacitidine or magrolimab).
* Females only: Pregnant or breastfeeding.
* Any other condition that would, in the Investigator's judgment, contraindicate the patient's participation in the clinical study due to safety concerns with clinical study procedures.
* Known inherited or acquired bleeding disorders.
* Clinical suspicion of active central nervous system (CNS) involvement by MDS.
* Significant medical diseases or conditions, including but not limited to, acute myocardial infarction within the last 6 months, unstable angina, uncontrolled diabetes, significant active infection and congestive heart failure (CHF) New York Heart Association (NYHA) class 3-4.
* Known or active hepatitis B or C infection or human immunodeficiency virus (HIV) infection in medical history.
* Prospective patients who, in the opinion of the principal investigator (PI), may not be able to comply with all study procedures (including compliance issues related to feasibility/logistics).