Few-layered MoSe2 nanosheets are significant for energy storage due to more active edges and improved conductivity. Herein, the cavity confinement effect of structure-efected UiO-66-NH2 is applied to host H3PMo12O40 units, which can be transformed into few-layered MoSe2 nanosheets confined into N,P-doped carbon polyhedrons (MoSe2/N,P-C) for fast Na+/K+-ion storage. Also, this unique architecture can provide sufficient active sites, alleviate the mechanical strain, and offer spacious channels for Na+/K+-ion transfer. Particularly, MoSe2/N,P-C(5:1) possesses superior sodium storage capability (316 mA h g(-1) at 2.0 A g(-1) within 300 cycles), promoted by the accelerated reaction kinetics and capacitive effect. In addition, an ultralong cycling stability with an expected capacity of 177 mA h g(-1) (1.0 A g(-1) after 1000 cycles) and a high rate capability (139.9 mA h g(-1) at 10.0 A g(-1)) can be achieved for the K+-ion storage. Ex situ Raman spectra and X-ray diffraction analysis imply a combined mechanism of a reversible intercalation-conversion process for active MoSe2 and partial reversibility of the N,P-C skeleton. In addition, the assembled MoSe2/N,P-C//Na3V2(PO4)(3)/C full cell also exhibits a capacity of 322.5 mA h g(-1) at 0.5 A g(-1), implying the potential application in practice.