The present study investigates the linear stability of stagnation boundary layer flow of viscoelastic Walters' liquid B in the presence of magnetic field and porous medium by solving modified Orr–Sommerfeld equation numerically using the Chebyshev collocation method. The model is characterized mainly by the elasticity number (E), the magnetic number (Q), and the permeability parameter (K) in addition to the Reynolds number(Re). The Prandtl boundary layer equations derived for the present model are converted through appropriate similarity transformations, to an ordinary differential equation whose solution describes the velocity, which has oscillatory behavior. The solution of generalized eigenvalue problem governing the stability of the boundary layer has an interesting eigenspectrum. The spectra for different values of E, K, and Q are shown to be a continuation of Newtonian eigenspectrum with the instability belongs to viscoelastic wall mode for certain range of parameters. It is shown that the role of elasticity number is to destabilize the viscoelastic boundary layer flow, whereas both magnetic field and porous medium have the stabilizing effect on the flow. These interesting features are further confirmed by performing the energy budget analysis on the perturbed quantities. Region of negative production due to the Reynolds stress as well as production due to viscous dissipation and viscoelastic contributions in the positive region, and there is reduction in the growth rate of kinetic energy that causes stability. Other physical mechanisms related to flow stability are discussed in detail.