We present a strategy of self-nanocavity confinement for substantially boosting the superior electrochemical hydrogen peroxide (H2O2) selectivity for conductive metal-organic framework (MOF) materials. By using operando synchrotron radiation X-ray adsorption fine structure and Fourier transform infrared spectroscopy analyses, the dissociation of key *OOH intermediates during the oxygen reduction reaction (ORR) is effectively suppressed over the self-nanocavity-confined X-Ni MOF (X = F, Cl, Br, or I) catalysts, contributing to a favorable two-electron ORR pathway for highly efficient H2O2 production. As a result, the as-prepared Br-confined Ni MOF catalyst significantly promotes H2O2 selectivity up to 90% in an alkaline solution, evidently outperforming the pristine Ni MOF catalyst (40%). Moreover, a maximal faradic efficiency of 86% with a high cumulative H2O2 yield rate of 596 mmol gcatalyst-1 h-1 for electrochemical H2O2 generation is achieved by the Br-confined Ni MOF catalyst.