  We prove explicit stability estimates for the sphere packing problem in
dimensions 8 and 24, showing that, in the lattice case, if a lattice is $\sim
\varepsilon$ close to satisfying the optimal density, then it is, in a suitable
sense, $O(\varepsilon^{1/2})$ close to the $E_8$ and Leech lattices,
respectively. In the periodic setting, we prove that, under the same
assumptions, we may take a large 'frame' through which our packing locally
looks like $E_8$ or $\Lambda_{24}.$
  Our methods make explicit use of the magic functions constructed by M.
Viazovska in dimension 8 and by H. Cohn, A. Kumar, S. Miller, the second
author, and M. Viazovska in dimension 24, together with results of independent
interest on the abstract stability of the lattices $E_8$ and $\Lambda_{24}.$
