Conversion-alloying type anode materials like metal sulfides draw great attention due to their considerable theoretical capacity for sodium-ion batteries (SIBs) and potassium-ion batteries (PIBs). However, poor conductivity, severe volume change, and harmful aggregation of the material during charge/discharge lead to unsatisfying electrochemical performance. Herein, a facile and green strategy for yolk-shell structure based on the principle of metal evaporation is proposed. SnS 2 nanoparticle is encapsulated in nitrogen-doped hollow carbon nanobox (SnS 2 @C). The carbon nanoboxes accommodate the volume change and aggregation of SnS 2 during cycling, and form 3D continuous conductive carbon matrix by close contact. The well-designed structure benefits greatly in conductivity and structural stability of the material. As expected, SnS 2 @C exhibits considerable capacity, superior cycling stability, and excellent rate capability in both SIBs and PIBs. Additionally, in situ Raman technology is unprecedentedly conducted to investigate the phase evolution of polysulfides. This work provides an avenue for facilely constructing stable and high-capacity metal dichalcogenide based anodes materials with optimized structure engineering. The proposed in-depth electrochemical measurements coupled with in situ and ex situ characterizations will provide fundamental understandings for the storage mechanism of metal dichalcogenides.