The sun gets its energy by nuclear fusion, and this creates a very hot outer layer. In fact the sun appears to us as a black body would when heated to about 6000 degC. You may be puzzled by reference...
The sun, like all stars, gets its energy from nuclear fusion. The Earth is only habitable for life because of the sun's radiant energy which reaches us. So we all depend on nuclear energy.