Unfortunately most of us don't care to have our yards look like mine fields. Unfortunately accidents often happen to dogs running at large and these can be quite expensive for the owner if not fatal for the dog. Escaping also becomes a habit for a dog - one that can be very difficult to break. This can lead to many health problems. There is a simple prevention for boredom and loneliness for most pet dogs.
Dogs are pack animals and the owners are the members of the dogs' pack.
Don't isolate the dog endlessly. This doesn't mean that he should never be apart from you. It means that when you are home the dog is with you in the house. It means that the dog sleeps in the house. It means that the dog is part of family activities.