In the present study, an innovative electrochemical sensing platform was established for sensitive detection of NO2—. This sensor was developed using CoFe alloy encapsulated in nitrogen-doped carbon nanocubes (named as CoFe@NC-NCS), synthesized through the calcination of polydopamine-coated CoFe Prussian-blue analogues (CoFe-PBA@PDA). The morphological and electrochemical characterization reveals that the CoFe@NC-NCS possesses high electrocatalytic activity for electrochemical quantitation of NO2—, ascribed to the huge surface area and plentiful active positions, benefiting from the porous, hollow, and core–shell structure of CoFe@NC-NCS. Under the optimal conditions, CoFe@NC-NCS/GCE possessed remarkable sensing performance for NO2— with wide liner ranges and a detection limit of 0.015 μM. NO2— recovery experiments in real samples exhibited recoveries in the range of 98.8–103.5%. Hence, the CoFe@NC-NCS shows great promise for the construction of electrochemical sensor with more potential application.