In situ CO2 foams (ISCF) are studied systematically by combining in situ CO2 gas reactants (carbonate anhydrous, hydrochloric acid) and bio‐based surfactant. Sandpack flooding experiments at 60°C along with PVT experiments were carried out to analyze the oil displacement mechanisms. The results showed that ISCF could increase oil recovery from heterogeneous multilayer formation of permeability ratio over 6, and displacement efficiency increased with the injection volume increased before the injection of 1 PV. The incremental oil recovery by ISCF was much greater than that of conventional foam or in situ CO2 (ISC) without foam under the same injection conditions. The generated CO2 foam could reduce the interfacial tension between displacement phase and displaced phase effectively which contributed to the great increase in capillary number. The CO2 dissolution greatly reduced the viscosity of crude oil, and the highest viscosity reduction rate at 60°C could be as high as 98%. The Ca2+ concentration of produced liquids analysis revealed the ISCF could distribute intelligently the acid in heterogeneous formations.