The problem is, dogs are not born with any instinctive fear of vehicles, they do not know what a road is, as opposed to a sidewalk, and there is little to naturally deter them from running out onto a road, unless specifically taught not to do so. While the safest method to prevent your dog from running out onto the street is to keep your dog on a leash, even the best-laid plans can go awry. Leashes break, yard gates get left open, people accidentally drop leashes, knots come untied, there is a myriad of ways your dog could be put in a situation where he is free to run into traffic. So, teaching your dog not to run into the street, even if you always keep him on a leash, is a great idea to prevent the unthinkable.
Training your dog to avoid roadways should be done as early as possible. Puppies are unpredictable and can be easily distracted chasing a ball or squirrel out onto a roadway. Adult dogs that have not developed a healthy caution of roadways should also be taught not to run out on the road. This is a critical safety issue for your dog. There are several exercises that can be used to gain control over your dog and prevent them from running out onto the street, which include teaching your dog to distinguish the street from the sidewalk and providing alternate behaviors and off-leash commands.
You will need a leash and a relatively safe roadway, in a quiet neighborhood, with little traffic to ensure your dog's safety during training, and some time to walk your dog and expose him to streets and traffic. As an added benefit, all that exercise will be good for you, your dog, and your relationship! You can work on leash walking manners while you are at it, teach your dog to heel, and practice being in control around other dogs, people and new experiences. You should take along some treats to reward your dog for obeying commands and following your directions. If you are in a rural setting, or in a situation where your dog could be unsupervised with access to streets, you may choose to create a negative association with a shock collar and whistle. Read all instructions with a shock collar to ensure you understand its correct usage.