Nanoconfined SnS in 3D interconnected macroporous carbon (3D SnS/C) has been produced using silica opals as template following a carbonization and sulfuration route. The electrochemical properties of the 3D SnS/C were examined comprehensively as anode materials for lithium/sodium ion batteries (LIBs/SIBs). It delivers a high specific capacity of 869 mA h g −1 at 1 A g −1 after 1000 cycles in LIBs and 400 mA h g −1 at 100 mA g −1 after 100 cycles in SIBs. The rate performance is also excellent (550 mA h g −1 at 3 A g −1 in LIBs and 220.9 mA h g −1 at 5 A g −1 in SIBs). The outstanding electrochemical performance of the 3D SnS/C is ascribed to its 3D porous carbon interconnected structure and nanoconfined SnS nanoparticles distributing broadly in carbon matrix, which not only improve the conductivity, but also keep the structure integrity, and as a result of enhancing the cycling stability of the material. In addition, this facile and novelty strategy can be potentially utilized for preparing other 3D metal sulfides interconnected macroporous carbon composite for energy storage.