The Earth's atmosphere and atmospheric layers are kept in place primarily by the Earth's own gravity, not the gravity of the sun. Gravity is what holds the gases of the atmosphere close to the Earth's surface, preventing them from escaping into space.