The filament needs to be protected from the air, so it is inside the bulb, and the air in the bulb is either removed (a vacuum) or more often, replaced with a noble gas that doesn't affect anything, like neon or argon. Only about 3% of the energy that goes into an incandescent light bulb actually makes light, the rest makes heat. That's one of the reasons LED's are more efficient.