Overheating, software errors, incorrect permissions and malfunctioning hardware can each cause a MacBook to suddenly shut itself down. Fixing software glitches or heating problems can often be fixed yourself at no cost, but if an internal component is malfunctioning, you may have to take the MacBook in for repair.
Occasionally, the hardware inside your computer can deteriorate or simply be defective. The MacBook's logic board is one of the most common sources of hardware problems. If you have repaired your operating system and performed all the other steps above, you have narrowed causes down to where the problem almost exclusively must be a hardware problem. Unfortunately, if this is the case, the hardware itself will need to be replaced, meaning that you'll need to make an appointment with an Apple Lab.