When a lawn mower has trouble staying on, it could be any number of problems. The spark plug may not be sending enough spark to the motor. Maybe the engine is flooded with fuel. Even something as simple as not pushing in the choke could be the problem. The only way to figure out the problem is to inspect the motor and its many parts. Wear old clothes as you will surely end up dirty.
Inspect the air filter. If it is clogged, the motor will shut off because no clean air is getting into the engine, causing it to overheat. It is a large rectangle on the side or on top of the motor. Unscrew the plate that secures the filter with a Phillips-head screwdriver. Wash it out with soap and water and put it back in place.
Pull the spark plug out of the black hose running alongside the motor. Check for any cracks, especially around the forked head. If the spark plug is cracked, it will not generate enough spark to fully start the engine.
Press your thumb and index finger on the fuel line. If it is bulging, there is too much fuel going into the engine at once, which chokes it. The best way to remedy this is to rest the mower for a day as some of the fuel will go back into the fuel tank after awhile.
Ensure that the full-choke position is turned on when you start the mower. Sometimes if you only use the half-choke position, it will only start for a second because it is not getting enough fuel into the carburetor. Starting it in full-choke will provide more fuel into the carburetor.