First and foremost, do not panic. Panic may considerably reduce the amount of time that you have for survival. In a state of panic, a person uses oxygen a lot more actively. Living in a coffin is possible for one or two hours provided that you do not panic. If you can meditate, try to do it to relax as much as possible to be able to gather and think more clearly.
Check if you have any cellular gadgets with you. Nowadays, people may often be buried with their cell phones or other means of communication. If this is your case, try to contact your relatives or friends. As soon as you do it, relax and meditate further to save your oxygen.
If there is no cellular phone at hand, it does not mean that you are going to die. Given that you are still alive in a coffin with a limited amount of air in it means that you were buried a short while ago. Therefore, the soil above the coffin is still soft enough.
Lift the shirt over your head turning it inside out, but not completely. Tie the shirt at the top to make a bag around your head. This will create something like a mask to protect you from inhaling dust.
If the coffin has not been damaged with the weight of the soil, use your legs to make a hole in the coffin. The best place to do it is the middle part of the lid.
When you break the lid with your legs, use your hands and feet to push the soil that enters the hole to the edges of the coffin. Fill the coffin with the soil firming it in a way not to lose an opportunity to stick your head and shoulders into the hole.
When you fill the coffin with soil as much as you can, try to do your best to stand up through the hole in the lid of the coffin. Most likely, you will have to make the hole in the lid larger, but it will be not hard to do if the coffin was cheap.
As soon as you finally manage to stick your head out on the surface and breathe freely, you can panic as much as you can calling for help. If no one comes to your rescue, pull yourself out of the pit wriggling like a worm.
If you were buried in a steel coffin, the best thing that you can do in this case is to make as much noise as possible by knocking, for example, your belt buckle on the coffin. Someone may still be near the grave.
Most importantly, lighting a match or a lighter, if you have one, is a bad idea. An open fire will quickly destroy all of the oxygen inside.