How does the Sun work?
The Sun is a giant, natural thermonuclear reactor that converts hydrogen to helium in its core to produce the heat we sense on our faces as sunshine.
Why does this reactor not explode as a thermonuclear bomb? The Sun is held together in an equilibrium state by the mutual gravitational attraction between all its atoms acting to compress the solar center. These gravitational forces produce and contain the nuclear reactions taking place there. The solar atmosphere outside the energy generating core adjusts itself to carry the enormous amount of energy that emerges from the surface in the form of radiation.
This is the basic idea behind the existence of all stars beginning with gravitational attraction and compression of a gas cloud to the beginning of nuclear energy generation and, finally, to the exhaustion of the nuclear fuel and death of the star.