This is one of the most common problems you can have in the early spring when you pull out the lawn mower for the first time. The mower will run for a few seconds and then it will die as if you shut off a switch.
Most of the time this is caused by not using a fuel stabilizer like Ethanol Shield or Stabil . When your gasoline or diesel fuel is stabilized, it prevents the fuel from phase separating into different parts and then drying up while inside of a carburetor or fuel injected mower. Once dried up, they plug up those vital ports that allow the engine to continue to run. Just enough fuel will enter the engine to start but the full throttle it needs to run will happen because the engine is starving for fuel.
The carburetor will need disassembled to clean all the ports properly. In some cases you can remove the float bowl screw at the bottom of the bowl and clean out the main jet that is in that screw. On Chinese and Japanese lawn mower engines, the idle jet must be cleaned in addition to the main jet and emulsion tube which is inside the fuel tower that runs vertically through the carburetor. The idle jet is located inside a plastic plug that is held in place by the idle speed control screw that is also plastic. The idle jet has a very small port size so use something like one strand of wire from a small electrical wire.
Use carburetor cleaner to spray out all the ports and then blow them out with low pressure compressed air. Re-assemble the carburetor and install and test to see if it works as it should. It is runs but surges, you still have a blockage somewhere in the carburetor that will need to be cleaned. Repeat the process until you find that port that is blocked. You could also have an air leak and may not have the bolts that hold the carburetor tight enough.
Make sure you have fresh fuel in the engine as well because stale fuel will not light off very well or produce the power you need to keep the engine running. By cleaning your carburetor, you will fix the problem of my lawn mower dies after starting.