Gas pipes - why does gas burn "outwards?"
A gas flame is essentially a (chemical) reaction front, a (thin) layer in which a hydrocarbon (e.g. methane) is oxidised acc.:
$$\text{CH}_4(g) + 2\text{O}_2(g) \to \text{CO}_2(g) + 2\text{H}_2\text{O}(g)$$
This oxidation reaction is colloquially known as burning or combustion. It's obvious from the equation the combustion needs requisite amounts of oxygen, $\text{O}_2$, coming from the air which contains about $20$ percent of it.
However, in order for the reaction to be viable, the ratio of combustant to oxygen, here:
$$\frac{\text{CH}_4}{\text{O}_2}$$
must fall within certain limits. Too much $\text{CH}_4$ and combustion is not possible. Similarly too much $\text{O}_2$ and the reaction does not proceed.
The ratio is optimal in the reaction front, but not outside of it. Inside the pipe there's not enough oxygen to sustain combustion.
There is also such a thing as a reverse (or inverse) flame. In this video, oxygen burns inside a propane atmosphere:
Photo above: oxygen burning in propane.
Below for comparison, propane burning in air:
Gert explained why the flame can't travel back into the cylinder (because there's no oxygen). However, that actually doesn't explain why the flame doesn't travel into the burner itself, because burners (in particular Bunsen/Teclu burners, but hob/camping burners as well) actually pre-mix the gas with air inside the burner tube, but still it only burns outside!
The reason this works is that the burner output forms a flame arrester. It is made of thermally conductive metal, which keeps the gas that streams out of the burner openings cool. Moreover, the holes of some (most? not sure) burners are terminated with a bit of wire mesh, which also prevents heat front from eating “into the interior” of the gas stream. And the gas, even when mixed with oxygen, can only burn at sufficiently high temperature. Normally the flame sustains this temperature by its own exothermic reaction, but by seeping away that heat sufficiently fast is is possible to prevent burn in the tube.
The reason to pre-mix gas and air is that it leads to a cleaner – no soot – and also hotter flame.
Combustion requires the ratio of fuel and oxygen in the air to fall within a specific range, which is different for different types of fuel. There are different cutoff points for ignition, for sustained burning, and for deflagration. Too far from the gas source, there's not enough gas to burn. Inside the pipe, there's too much gas and not enough oxygen.