There are two main mechanisms that on Earth can produce the leaking of its atmosphere into space.
First mechanism is by thermal escape, which means that gas molecules can achieve from time to time (by collisions between them) such a high speed that they can escape into space (for this the speed of gas molecules need to be higher than the first cosmic speed). In the kinetic theory of gases it is shown that the average (root mean square) molecular speed is
which gives a value of about `v_(rms)=500 m/s =0.5 km/s` at room temperature for both `N_2` and `O_2` gases (that make 99% of Earth atmosphere). Since the first cosmic speed for Earth is `v_1 =11.2 (km)/s` and gas molecules follow a Maxwell-Boltzmann distribution only a very small percent of the gases escape in outer space through this mechanism.
Second mechanism is the depletion by the solar winds. In a few words, since particles that make solar winds (mostly protons - hydrogen nuclei and alpha particles - He nuclei) have enough kinetic energies they can theoretically pass this energy by collisions to the atmosphere molecules, this way the gas molecules being able to achieve escape velocities. Since Earth has its own magnetic field, solar winds are deflected away from the atmosphere. Because of this only a tenth of percent of the Earth atmosphere escapes this way at poles.
Thus the atmosphere of the earth does not escape into space because of three factors: Earth gravity, atmosphere temperature to low and presence of magnetic field of Earth.