You can only discourage. Protected coop so they can't get in and massacre, electric fence around run will usually keep out a fox. You can get portable kits with 50m of fencing and battery power, solar etc. 50m fencing makes quite a big pasture for them.
I use motion-detected lights to...