Developing efficient catalysts for steering the electrochemical CO2 reduction reaction (CO2RR) toward high-value chemicals beyond CO and formic acid is highly desirable. Herein, we have developed copper-based catalysts confined within a rationally designed covalent triazine framework (CTF-B), featuring a CuN2Cl2 structure, for selective CO2RR to hydrocarbons with a maximum Faradaic efficiency (FE) of 81.3% and an FE of C2H4 up to 30.6%. Operando X-ray adsorption fine structure analyses reveal the potential-driven dynamic formation of Cu atomic clusters, together with the time-dependent and Cu-content-dependent CO2RR performance associated with the catalyst activation, definitively uncovering that the aggregated Cu clusters confined within CTF-B are the active sites. A further probing experiment of CO electroreduction not only verifies that CO is one of the key intermediates for the CO2RR but also demonstrates the improved selectivity to C2 chemicals, with a maximum FE of 68.4% (C2H4, 35.0%; acetate, 33.4%), possibly originating from the accelerative C–C coupling reaction due to the increased CO coverage and enhanced local pH in CO-saturated electrolyte. Interestingly, acetate is identified as the only liquid product, mostly likely benefiting from the dominant low-coordination active sites of confined Cu aggregation and favorable chemical confinement environment of CTF-B. The strategy of constructing efficient metalloelectrocatalysts by means of confinement in a covalent organic framework along with operando identification of active sites sheds light on the rational catalyst design and structure–property relationship.