The structure of an artificial excavation foundation pit is a typical semi-enclosed space, wherein the working space is small, and the natural ventilation is not smooth. This makes it easy to cause the accumulation of harmful gases and threaten the safety of operators. In this work, an artificial excavation foundation pit was used as the study area. Computational fluid dynamics software was employed to simulate the dynamic change law of the gas environment of artificial excavation foundation pits of different sizes (diameter and depth) under the action of natural and mechanical ventilation. The simulation results showed that under natural ventilation, the harmful gas barely dissipates, and thus, mechanical ventilation must be adopted. Under mechanical ventilation conditions, at the same digging depth, the lower the position of the diffusion source, the faster the mass fraction of harmful gas at the monitoring point when it reaches peak value; the deeper the hole, the longer the mass fraction of harmful gases to reach the peak value at the monitoring point, and the more difficult it is for the harmful gas to diffuse. Further, the larger the diameter, the faster the mass fraction of the monitoring point when it reaches the peak, while diameter size has little effect on the dissipation rate. By analyzing the law, a prediction model for changing carbon dioxide gas concentration at a distance of 1.2 m from the bottom of the foundation pit was established. The model can simulate and predict changes in harmful gas concentration in artificial excavation foundation pits.