We investigate the excitation of magnetoacoustic–gravity waves generated from localized pulses in the gas pressure as well as in the vertical component of velocity. These pulses are initially launched at the top of the solar photosphere, which is permeated by a weak magnetic field. We investigate three different configurations of the background magnetic field lines: horizontal, vertical, and oblique to the gravitational force. We numerically model magnetoacoustic–gravity waves by implementing a realistic (VAL-C) model of the solar temperature. We solve the two-dimensional ideal magnetohydrodynamic equations numerically with the use of the FLASH code to simulate the dynamics of the lower solar atmosphere. The initial pulses result in shocks at higher altitudes. Our numerical simulations reveal that a small-amplitude initial pulse can produce magnetoacoustic–gravity waves, which are later reflected from the transition region due to the large-temperature gradient. The cavities in the lower solar atmosphere are found to have the best conditions to act as a resonator for various oscillations, including their trapping and leakage into the higher atmosphere. Our numerical simulations successfully model the excitation of such wave modes, their reflection and trapping, as well as the associated plasma dynamics.