Metal−organic framework materials can be converted into carbon-based nanoporous materials by pyrolysis, which have a wide range of applications in energy storage. Here, we design special interface engineering to combine the carbon skeleton and nitrogen-doped carbon nanotubes (CNTs) with the transition metal compounds (TMCs) well, which mitigates the bulk effect of the TMCs and improves the conductivity of the electrodes. Zeolitic imidazolate framework-67 is used as a precursor to form a carbon skeleton and a large number of nitrogen-doped CNTs by pyrolysis followed by the in situ formation of Co 3 O 4 and CoS 2 , and finally, Co 3 O 4 @CNTs and CoS 2 @CNTs are synthesized. The obtained anode electrodes exhibit a long cycle life and high-rate properties. In lithium-ion batteries (LIBs), Co 3 O 4 @CNTs have a high capacity of 581 mAh g −1 at a high current of 5 A g −1 , and their reversible capacity is still 1037.6 mAh g −1 after 200 cycles at 1 A g −1 . In sodium-ion batteries (SIBs), CoS 2 @CNTs have a capacity of 859.9 mAh g −1 at 0.1 A g −1 and can be retained at 801.2 mAh g −1 after 50 cycles. The unique interface engineering and excellent electrochemical properties make them ideal anode materials for high-rate, long-life LIBs and SIBs.