A compact, sensitive and stable hollow waveguide (HWG) mid-infrared gas sensor, based on gas absorption lines using wavelength modulation spectroscopy with a second harmonic (WMS-2ƒ) detection scheme, was developed for simultaneous measurements of ambient CO2 and water vapor. Optimization of the laser modulation parameters and pressure parameter in the HWG are performed to improve the strength of the WMS-2f signal and hence the detection limit, where 14.5-time for CO2 and 8.5-time for water vapor improvement in system detection limit is achieved compared to those working at 1atm. The stability of the sensor has been improved significantly by optimizing environmental disturbances, incoupling alignment of the HWG and laser scanning frequency. An Allan variance analysis shows detection limit of the developed sensor of ∼3 ppmv for CO2 and 0.018% for water vapor, which correspond to an absorbance of 2.4 × 10-5 and 2.7 × 10-5, with a stability time of 160 s, respectively. Ambient CO2 and water vapor measurement have been performed in two days in winter and spring separately. The measurement precision is further improved by applying a Kalman adaptive filter. The HWG gas sensor demonstrates the ability in environmental monitoring and the potential to be used in other areas, such as industrial production and biomedical diagnosis.