Rational design of high-capacity nanosized composites as anode nanomaterials is crucial to boosting electrochemical performances towards large-scale application for lithium- and sodium-ion batteries (LIBs and SIBs). The small sizes and homogeneous dimensional size distributions are achieved typically by either the surface confinement on the underlying supports, or the encapsulation confinement within the precursors (such as metal-organic frameworks). Herein, we report the ultrasmall NiS2 nanodots on reduced graphene oxide (NiS2/N,S-rGO) synthesized via interlayer confinement as anode nanomaterials for LIBs and SIBs. The composite is synthesized by pyrolyzing a host/guest precursor of sodium dodecyl sulfate ion/[NiEDTA]2��� anions co-intercalated MgAl-layered double hydroxide LDH host, without additional sulfur source. The host/guest-derived interlayer nanoconfinement enables the composite to integrate the advantageous features: low-content active NiS2 nanodots (11.0 wt%) with a mean size of 3.8 �� 0.5 nm, high-content N,S-rGO (89.0 wt%), as well as a large specific surface area and mesopore size distribution. The composite used as anode nanomaterial exhibits reversible capacities of 801.2 mAh g���1 after 100 cycles at 100 mA g���1 for LIBs, and 207.7 mAh g���1 after 200 cycles at 0.1 A g���1 for SIBs, which are greatly higher than those of the pristine N,S-rGO without NiS2 nanodots. The enhancement is experimentally supported by the low charge transfer resistance, high capacitive-controlled contribution, and good structural stability. Our guest/host-based interlayer nanoconfinement can promise an effective synthesis strategy for designing various nanosized anodes for electrochemical energy storage.