If fuel cannot get through the fuel filter, it will stop running.
clogged fuel filter
Not nearly enough information is given. BUT - you can start by looking at these possibilities: a clogged fuel filter - a failing fuel pump - clogged injector nozzles.
Can be lots of things but sounds like a fuel pump failing or clogged fuel filter.
Could be a number of reasons.. you could be losing compression, you could have a clogged diesel particulate filter (if so equipped), worn components... you'd need have have it inspected to narrow down the cause.
For starters change the fuel filter
Most common culprit in surging is a dirty/clogged air filter.
Change the fuel filter first,
Defective fuel pump, or clogged fuel filter is one cause.
Dirty fuel filter will do that. Defective "kill" switch.
The air filter is probably dirty or clogged,
It will cause those and eventually will shut down your engine until the filter is changed or cleaned.
Main causes: Lack of compression, Bad spark plug, no fuel, bad fuel bump fuse, clogged fuel fiter, or clogged fuel injector(s)