How you secure the box will depend on the location but for any sort of shelving or smooth surface, Command Strips are a great place to start. I suggest the velcro version.
As a general guideline, ensure enough free space in front of the box equal to the length of your cat. More is better, but that’s the minimum you should look for.
To prevent pets and children from accessing the litter box - going for a higher spot can control access for both kids and pups, but so can many other options.