We investigated how the magnetic field in solar active regions ( ARs ) controls flare activity , i.e. , whether a confined or eruptive flare occurs . We analyzed 44 flares of GOES class M5.0 and larger that occurred during 2011–2015 . We used 3D potential magnetic field models to study their location ( using the flare distance from the flux-weighted AR center d _ { \mathrm { FC } } ) and the strength of the magnetic field in the corona above ( via decay index n and flux ratio ) . We also present a first systematic study of the orientation of the coronal magnetic field , using the orientation \varphi of the flare-relevant polarity inversion line as a measure . We analyzed all quantities with respect to the size of the underlying dipole field , characterized by the distance between the opposite-polarity centers , d _ { \mathrm { PC } } . Flares originating from underneath the AR dipole ( d _ { \mathrm { FC } } / d _ { \mathrm { PC } } < 0.5 ) tend to be eruptive if launched from compact ARs ( d _ { \mathrm { PC } } \leq 60 Mm ) and confined if launched from extended ARs . Flares ejected from the periphery of ARs ( d _ { \mathrm { FC } } / d _ { \mathrm { PC } } > 0.5 ) are predominantly eruptive . In confined events the flare-relevant field adjusts its orientation quickly to that of the underlying dipole with height ( \Delta \varphi \gtrsim 40 ^ { \circ } until the apex of the dipole field ) , in contrast to eruptive events where it changes more slowly with height . The critical height for torus instability , h _ { \mathrm { crit } } = h ( n = 1.5 ) , discriminates best between confined ( h _ { \mathrm { crit } } \gtrsim 40 Mm ) and eruptive flares ( h _ { \mathrm { crit } } \lesssim 40 Mm ) . It discriminates better than \Delta \varphi , implying that the decay of the confining field plays a stronger role than its orientation at different heights .