scoreboard players tag @a[tag=Spectator] add PreventEscape
execute @a[tag=Spectator] ~ ~ ~ detect ~ 0 ~ stone 0 scoreboard players tag @s remove PreventEscape
scoreboard players tag @a[tag=Spectator,x=-500,y=0,z=-500,dx=1000,dy=90,dz=1000] add PreventEscape