Question: It seems I've been seeing a lot of uses for foam on this site, from a weapon to a spaceship defense mechanism. However, the details on what the foam is made of and how it works always seem lacking to me; thus, I worry that many of these foams are just science fiction. 

My question is **is there a foam that can be used to quickly construct airtight walls solid enough to keep humans out?** I imagine using this foam on a spaceship to trap the enemy, or alternately to fix hull breaches. Perhaps there is a fast-acting variant that can be used as a grenade to immobilize enemies. As it is a foam, it could be carried around much more easily than other wall-building materials, thus I could outfit my space marines with a few cans apiece. 

So, does this foaming material exist, or is there a theoritcal way to produce it? If so, how big would the initial substance be, and how long would it take to dry/harden? 

The foam need not be activated by air; on the contrary, it would be great if it contains its own reactants, and can be activated in a vacuum. 

It need not last; it should only be functional for a minimum of a couple hours. If it breaks down after that, that's fine. 

I would like it to be as strong as possible. If it can get to concrete levels, that would be best, but as long as it's very difficult for a human to burrow through that'll work.

Answer: 
Foam is, by definition, simply a lot of bubbles.

**Bubbles don't work in a vacuum.** (Theoretically they do, but their behavior isn't interesting since they explode — emphasis on *explode* — immediately.)

So this gives you a few upsides and a few downsides. I could see a viable 'cement-like' foam that hardens *because* the water or other liquid with which it is inflated immediately evacuates and vaporizes in outer space (e.g. when repairing the wall of a spacecraft) leaving only the igneous-rock-like matrix behind.

@AndyD273 points out quite correctly that foam in a vacuum expands far more than it does in atmospheric pressure. But remember that this also means that you have far thinner bubbles in much more space, leaving you with a much weaker structure. 

Your wall material would have to be pretty (1) flexible and (2) strong to begin with, even before spraying.

**But this gets more complicated when working in atmospheric pressure.** You're limited at the very *fastest* by the entropy-fueled diffusion and expansion of gas. This leads me to believe that a foam used as a quick-spray detainment weapon would need to have *highly* reactive gaseous compounds that are stored separately and then injected together into the foam as it's released, causing that sort of high-speed expansion you're looking for. (Side-benefit: **Such a quick expansion would either release or absorb a lot of heat**, depending on the mechanism. I could viably see your foam curing due to its own high heat, or freezing due to its below-zero temperatures.)

---

Side-note: Anyone who's tried to use their hands to tear that foam insulation stuff knows from experience that, even though it's *possible*, it's an enormous pain to actually do. Easy to dent it, not easy to rip.

**[EDIT]**: As @JDługosz points out, a foam in a vacuum can cure from the outside in... But that would lead to a pressurized interior. And [we all know what happens](https://www.youtube.com/watch?v=6V2eCFsDkK0) when brittle materials harden on the outside and leave a still-liquid, still-cooling interior...
Shotcrete <https://en.wikipedia.org/wiki/Shotcrete> would probably be one of the best known structural foams currently available but there are certainly others available and is certainly able to set creating a gas tight surface and more than capable of keeping humans in or out. Good for making a permanent repair to that hole in your lunar bio-dome, probably heavier than you would want for a spaceship repair, and certainly too slow setting for foe suppression.
For your emergency hull repair you would want a lighter weight substrate to quickly fill the gap and then use a heavier solid foam for the permanent repair
For foe suppression just stick to sticky foam <https://en.wikipedia.org/wiki/Sticky_foam>.