Yes, actually. In all League-inspected and -approved fields, there are energy shields erected to disrupt distance attacks, protect spectators, and minimize damage to the stadium or gym. Higher-powered shields are additionally placed around spectator seating to prevent a pokémon or its attacks from passing through. (The weaker shields don’t prevent pokémon from flying right through, which allows them to use high-altitude moves such as Fly or Sky Attack … or, well. Fly out of bounds, in any case.)
Of course, this is secondary to proper training. Most trainers will teach their pokémon to stay within a field anyway, if only because of the rules concerning TKOs.
In other words, rest assured watching a battle from the stands is perfectly safe.