How does the sun work?

The sun is gigantic nuclear fusion engine. It works on the principles of stallar nucleosynthesis, and you can use the link below to go to that question and learn more.

As nuclear fusion occurs in the Suns core, the temperature increases. This expands the outer envelope of the Sun (Like a heated balloon), this expansion decreases the pressure on the core, which then decreases the amount of nuclear fusion that occurs, and thus temperature. This reduction causes the outer envelope to contract, which causes an increase in pressure, which causes an increase in nuclear fusion, which creates more heat, the outer envelope expands and well…. ad infinitum.