The stabilization of a foam is caused by van der Waals forces between the molecules in the foam, electrical double layers created by dipolar surfactants, and the Marangoni effect, which acts as a restoring force to the lamellae.
The Marangoni effect depends on the liquid that is foaming being impure. Generally, surfactants in the solution decrease the surface tension. The surfactants also clump together on the surface and form a layer as shown below.
For the Marangoni effect to occur, the foam must be indented as shown in the first picture. This indentation increases local surface area. Surfactants have a larger diffusion time than the bulk of the solution—so the surfactants are less concentrated in the indentation.
Also, surface stretching makes the surface tension of the indented spot greater than the surrounding area. Consequentially—since diffusion time for the surfactants is large—the Marangoni effect has time to take place. The difference in surface tension creates a gradient, which instigates fluid flow from areas of lower surface tension to areas of higher surface tension. The second picture shows the film at equilibrium after the Marangoni effect has taken place.
Curing a foam solidifies it, making it indefinitely stable at STP.