Diesel engine dies

The intermittent nature of this problem lends itself to an electrical issue. The diesel doesn’t use spark plugs so the electrical problem involves the fuel delivery system, but where?

I wonder about the fuel pump(s). I believe you have more than one. One pump provides a good flow of fuel from the tank to the motor. The second pump takes that fuel and provides higher pressures to fuel injectors. One of the fuel pumps could be bad. Fuel pumps can fail intermittently until they go out completely.

Electricity is used in the sensors and the computer system telling the fuel injectors when to squirt the fuel and how much fuel per squirt. A bad connection, bad sensor, or bad ECM could be the culprit. The ignition switch is part of this system. As is the “anti shutter” solenoid mentioned @JosephEMeehan.

Finally, you need fuel filters on a diesel and they get gunked up by dirt, and water. Have the fuel filters been changed regularly over the life of the vehicle, and were they changed recently?