A gas pocket can form in a few different ways. With aluminum, hydrogen may fall out of suspension and fill voids with hydrogen gas.
It is possible that the mold tool may have been partially or completely vacated or vented as the cavity filled. Air that is trapped in this manner is called entrained air.
In addition to the liquids mixed with the molten metal, other liquids may be injected along with it. Among these might be mold release agents, hydraulic fluid leaks or even humidity. It is possible to vaporize and create gas bubbles from any of these substances. A liquid or oil that does not evaporate can become a contaminant which can lead to particle inclusions in the final product.