Long-cycling of anode nanomaterials is crucial for promoting lithium-ion batteries (LIBs) and sodium-ion batteries (SIBs) towards the further practical applications. Anode nanomaterials, such as transition-metal sulfides (TMSs), are conventionally prepared via sulfuration with additional conventional sulfur sources. Herein, we prepare bimetallic sulfide (Co 0.83 Fe 0.17 ) 9 S 8 nanoparticles confined within coral-like N,S co-doped carbon scaffolds ((Co 0.83 Fe 0.17 ) 9 S 8 /N,S-C) as anode nanomaterials for LIBs and SIBs, without introducing additional sulfur source. The (Co 0.83 Fe 0.17 ) 9 S 8 /N,S-C composite is eco-synthesized by direct pyrolysis of a mixture of metanilic acid intercalated CoFe-LDH and acid yellow 49 (AY49), thus endowed with the integrated advantageous features: bimetallic (Co 0.83 Fe 0.17 ) 9 S 8 , N,S co-doped carbon scaffold (14.2 wt%), the appropriate specific surface area and mesoporous structure. The electrochemical testing demonstrates that the composite exhibits a reversible capacity of 948.8 mAh g -1 after 80 cycles at 0.1 A g -1 for LIBs, and a decent reversible capacity of 392.9 mAh g -1 after 50 cycles at 0.1 A g -1 for SIBs, which are both superior to those of the Co 9 S 8 /N,S-C counterpart. The enhancement is supported by the result of low charge resistance determined by electrochemical impedance spectroscopy. Our results may provide an eco-efficient synthetic method for the preparation of TMSs for energy storage.