There wasn't any proper mechanism.
Air gunners were encouraged to imagine "an arc of sky" or a "circle of sky" - but of course that was based on AirMin notions of a nice tight steady 1930s-airshow formation, ploughing steadily into Hunland with no vertical or lateral relative movement.
The door-gunner in a USAAF heavy was particularly free in his choice of directions.
There were some physical angle-and-direction safeguards in place on most bomber and fighter-bomber aircraft to stop mid-upper shooting off his own tailplane (in the First Lot, BE2C Lewis-gunners were known occasionally to put a burst through the tail, the propellor, or even the pilot).
But apart from that, anything that strayed into line of sight in the general panic was able or even likely to get a line of 303s stitched across it, and there are many records of aircraft being wounded or even downed by friendly fire from within the defensive box.
And that of course is to say nothing of depositing bombloads onto the aircraft directly underneath. This was filmed several times, so Lord knows how often it actually happened, especially on night raids. And since in the examples I have seen it amputated a wing, the chances of the crew escaping the centrifugal force were not good.