Air mass factors (AMFs) are used in passive trace gas remote sensing for converting slant column densities (SCDs) to vertical column densities (VCDs). AMFs are traditionally computed with 1D radiative transfer models assuming horizontally homogeneous conditions. However, when observations are made with high spatial resolution in a heterogeneous atmosphere or above a heterogeneous surface, 3D effects may not be negligible. To study the importance of 3D effects on AMFs for different types of trace gas remote sensing, we implemented 1D-layer and 3D-box AMFs into the Monte carlo code for the phYSically correct Tracing of photons In Cloudy atmospheres (MYSTIC), a solver of the libRadtran radiative transfer model (RTM). The 3D-box AMF implementation is fully consistent with 1D-layer AMFs under horizontally homogeneous conditions and agrees very well ( < 5 % relative error) with 1D-layer AMFs computed by other RTMs for a wide range of scenarios. The 3D-box AMFs make it possible to visualize the 3D spatial distribution of the sensitivity of a trace gas observation, which we demonstrate with two examples. First, we computed 3D-box AMFs for ground-based multi-axis spectrometer (MAX-DOAS) observations for different viewing geometry and aerosol scenarios. The results illustrate how the sensitivity reduces with distance from the instrument and that a non-negligible part of the signal originates from outside the line of sight. Such information is invaluable for interpreting MAX-DOAS observations in heterogeneous environments such as urban areas. Second, 3D-box AMFs were used to generate synthetic nitrogen dioxide (NO2) SCDs for an air-borne imaging spectrometer observing the NO2 plume emitted from a tall stack. The plume was imaged under different solar zenith angles and solar azimuth angles. To demonstrate the limitations of classical 1D-layer AMFs, VCDs were then computed assuming horizontal homogeneity. As a result, the imaged NO2 plume was shifted in space, which led to a strong underestimation of the total VCDs in the plume maximum and an underestimation of the integrated line densities that can be used for estimating emissions from NO2 images. The two examples demonstrate the importance of 3D effects for several types of ground-based and airborne remote sensing when the atmosphere cannot be assumed to be horizontally homogeneous, which is typically the case in the vicinity of emission sources or in cities