  Gamma-ray bursts (GRBs) are powered by relativistic jets that exhibit
intermittency over a broad range of timescales - from $ \sim $ ms to seconds.
Previous numerical studies have shown that hydrodynamic (i.e., unmagnetized)
jets that are expelled from a variable engine are subject to strong mixing of
jet and cocoon material, which strongly inhibits the GRB emission. In this
paper we conduct 3D RMHD simulations of mildly magnetized jets with power
modulation over durations of 0.1 s and 1 s, and a steady magnetic field at
injection. We find that when the jet magnetization at the launching site is
$\sigma \sim 0.1$, the initial magnetization is amplified by shocks formed in
the flow to the point where it strongly suppresses baryon loading. We estimate
that a significant contamination can be avoided if the magnetic energy at
injection constitutes at least a few percent of the jet energy. The variability
timescales of the jet after it breaks out of the star are then governed by the
injection cycles rather than by the mixing process, suggesting that in practice
jet injection should fluctuate on timescales as short as $ \sim 10 $ ms in
order to account for the observed light curves. Better stability is found for
jets with shorter modulations. We conclude that for sufficiently hot jets, the
Lorentz factor near the photosphere can be high enough to allow efficient
photospheric emission. Our results imply that jets with $ 10^{-2} < \sigma < 1
$ injected by a variable engine with $ \sim 10 $ ms duty cycle are plausible
sources of long GRBs.
