We study the dynamics of a cavitation bubble near beds of sand of different grain sizes. We use high-speed imaging to observe the motion of the bubble and the sand for different values of the stand-off parameter
$\gamma$
(dimensionless bubble-boundary distance) between 0.3 and 5.3. Compared with a rigid boundary, we find that a granular boundary leads to bubbles with shorter lifetimes and reduced centroid displacements. Above
$\gamma \approx 1.3$
, the behaviour of the bubble is almost independent of the granularity of the sand. When the stand-off parameter lies between
$0.6$
and
$1.3$
, a mound of sand develops beneath the bubble, which can force the latter to assume a conical shape as it collapses. For
$\gamma \lesssim 0.6$
, the bubble develops a bell-shaped form, leading to the formation of thin and surprisingly fast micro-jets (
$v_{jet} > 1000\,{\rm m}\,{\rm s}^{-1}$
). Moreover, between
$\gamma \approx 1.3$
and
$\gamma \approx 0.3$
, granular jets erupt from the sand surface following the bubble collapse. We additionally develop a simple numerical model, based on the boundary integral method, to predict the dynamics of a cavitation bubble near a bed of sand, which we replace by an equivalent liquid. The simulations are remarkably consistent with experimental observations for values of
$\gamma$
down to
$1.3$
. We also show how the anisotropy parameter
$\zeta$
, a dimensionless version of the Kelvin impulse, can be adapted for the case of a nearby bed of sand and predict the displacement of the bubble centroid for
$\zeta \lesssim 0.08$
.