Electrocatalytic nitrogen (N2) reduction reaction (NRR) is an energy-saving approach to synthesize ammonia (NH3), which significantly depends on the development of high-efficiency electrocatalysts. Inspired by the catalytic microenvironment of enzymes, a series of yolk-shell nanostructures of monodispersed Au nanostars within porous organic polymers (POPs) have been successfully prepared via a self-sacrificing template strategy. The obtained yolk-shell nanocomposites have highly active Au nanostar cores and permeable POP shells for ambient electrocatalytic NRR to NH3. The hydrophobic properties of yolk-shell nanoreactors can be tailored accurately by engineering the POP shells at an atomic level, which greatly improves the N2 fixation performance by inhibiting the hydrogen evolution reaction, resulting in the unprecedented NH3 yield rate (∼109.1 μg h−1 mgcat.−1) and Faradaic efficiency (∼68.3 %). This work pioneers an effective strategy to construct tailor-made electrocatalysts for the N2-to-NH3 fixation.