We describe how AGN-produced cosmic rays form large X-ray cavities and radio lobes in the hot diffuse gas in galaxy groups and clusters . Cosmic rays are assumed to be produced in a small shocked region near the cavity center , such as at the working surface of a radio jet . The coupled equations for gasdynamics and cosmic ray diffusion are solved with various assumptions about the diffusion coefficient . To form large , long-lived cavities similar to those observed , the diffusion coefficient must not exceed \kappa \sim 10 ^ { 28 } cm ^ { 2 } s ^ { -1 } in the hot gas , very similar to values required in models of cosmic ray diffusion in the Milky Way . When { { { { \kappa \mathrel { \mathchoice { \lower 2.5 pt \vbox { \halign { \cr } $ \displaystyle \hfil < $% \cr$ \displaystyle \hfil \sim$ } } } { \lower 2.5 pt \vbox { \halign { \cr } $ \textstyle \hfil < % $ \cr$ \textstyle \hfil \sim$ } } } { \lower 2.5 pt \vbox { \halign { \cr } $ \scriptstyle \hfil < % $ \cr$ \scriptstyle \hfil \sim$ } } } { \lower 2.5 pt \vbox { \halign { \cr } $% \scriptscriptstyle \hfil < $ \cr$ \scriptscriptstyle \hfil \sim$ } } } } 10 ^ { 28 } cm ^ { 2 } s ^ { -1 } , cosmic rays are confined within the cavities for times comparable to the cavity buoyancy time , as implied by observations of X-ray cavities and their radio synchrotron emission . Collisions of proton cosmic rays with thermal plasma nuclei followed by \pi ^ { 0 } decays can result in enhanced gamma ray emission from the cavity walls .