It is a common misconception that fences are the only way to keep dogs in yards. In fact, there are many different ways to accomplish this goal. Fences can be expensive and not always practical for every situation so it helps to have other options as well.
Here are some of the most creative ways people have found to deter their pet from escaping out into the world:

Use a Water Gun
A water gun can be a great way to keep dogs from crossing boundaries. Simply squirt them when they get too close to the edge of the yard and they will quickly learn to stay away.
Plant Thorny Bushes
If you have a barking dog, consider planting some thorny bushes along the fence line. The thorns will discourage them from getting too close and make it difficult to escape.

Use a Motion Sensor
A motion sensor can be a great way to detect when a dog is trying to escape. When activated, it will spray the animal with water or emit an unpleasant noise.
Set up a Dog Kennel
If you are not home often or have a large yard, consider setting up a dog kennel. This will give your pet a designated area to stay in while you are away and will keep them from wandering off.
Use an Invisible Fence
An invisible fence is a great way to keep dogs from leaving the yard without having to build a fence. The system uses a wire that is buried in the ground and sends a signal to a receiver collar worn by the dog. When they get too close to the edge of the yard, they will receive a warning tone or shock.

Boundary Training
If you are consistent with boundary training, your dog will learn the limits of their territory. This can be done through verbal commands or using a leash to keep them close.
Long Pulley Line
If you have a large yard, consider using a long pulley line to keep your dog close by. This will allow them to roam around without getting too far from you and can be a great way to play fetch or give them some exercise.
Train Your Dog
Training your dog is always important, but it is especially crucial if you want them to stay in the yard. Make sure they know basic commands like “stay” and “come” and always reward them when they obey.s
With a little creativity, you can keep your dog safe and contained in the yard without resorting to a fence. Try out some of these methods and see what works best for your situation.