Every planet has an invisible conductor: its star. How the star shines and how active it is shape the fate of the planet's atmosphere. Young stars emit copious X-ray and ultraviolet radiation (XUV), which heats the upper layers of gas and can literally blow them off into space. Especially harsh are red dwarfs — small stars whose planets receive hundreds of times more of this radiation than Earth did in its youth.
Scientists have modeled this struggle. It turns out that around dwarfs, the zone where liquid water is possible shrinks by a factor of 6 over the first billion years. And the X-ray flux remains dangerous for billions more. For instance, planets in the TRAPPIST-1 system could barely hold onto thick atmospheres for most of their history. But there are exceptions: James Webb observations showed that LHS 1140 b has kept its gaseous envelope. So the outcome depends on many factors — the initial reservoir of gases, volcanic replenishment, and magnetic field.
Mars lost most of its atmosphere not only because of weak gravity, but also because its dynamo fell silent about 3.5 billion years ago. If Earth's core had cooled a bit faster, our planet might have shared its fate.
In Kim Stanley Robinson's Mars trilogy, colonists face the challenge of retaining an artificial atmosphere — essentially the same problem nature solves for exoplanets in the habitable zone.