Na and Li metals are ideal anodes for high-energy rechargeable batteries. However, their poor coulombic efficiency and the associated safety issues due to dendritic metal deposition and large volume changes during metallic plating/stripping are the major causes that persistently hinder their practical energy-storage applications. Herein, Zn-containing carbon nanostructures derived from typical zeolitic imidazolate framework-8 (ZIF-8) are proposed as advanced metal anode materials for both Na and Li metal batteries. The three-dimensional interconnected porous surfaces confine metallic Na and Li within the nanostructures, filling the carbon scaffold, and covering the electrode surface to form stable solid electrolyte interphases. Based on the metal nucleation and growth results obtained through various electrochemical tests, Zn incorporation and pore morphology have been revealed to be the key factors that regulate the metal nucleation and metallic plating/stripping during cycling. Thus, the incorporation of Zn in the closed pores of a carbon nanostructure improves the cycle performance, even in carbonate electrolytes, and produces stable Na and Li metallic anodes for next-generation rechargeable batteries.