A car that suddenly stalls and shuts off during driving could be caused by a number of things.
Clogged or bad fuel injectors, bad spark plugs, bad ignition coils, clogged fuel filter, or bad or failing fuel pump could all be causes of your vehicle shutting off when driving down the road.
An overheating engine could also cause the car to shut off while driving and then once cooled down it may decide to start up and run fine again for awhile.
Other problems such as electrical problems with the alternator or wires coming loose to the fuel pump where the fuel pump shuts off could all be causes of a car shutting off while driving.
Even faulty wiring that is shorting out or losing ground could cause cars to shut off so it's a good idea to get the car to a mechanic who can run some tests on the electrical system or even the fuel pump to determine the exact cause.