Context. In the fallback disk model for the persistent emission of anomalous X-ray pulsars (AXPs) and soft gamma-ray repeaters (SGRs), the hard X-ray emission arises from bulk-and thermal Comptonization of bremsstrahlung photons, which are generated in the accretion column. The relatively low X-ray luminosity of these sources implies a moderate transverse optical depth to electron scattering, with photons executing a small number of shock crossings before escaping sideways. Aims. We explore the range of spectral shapes that can be obtained with this model and characterize the most important parameter dependencies. Methods. We use a Monte Carlo code to study the crisscrossing of photons in a radiative shock in an accretion column and compute the resulting spectrum. Results. As expected, high-energy power-law X-ray spectra are produced in radiative shocks with photon-number spectral index Γ > ∼ 0.5. We find that the required transverse optical depth is 1 < ∼ τ ⊥ < ∼ 7. Such spectra are observed in low-luminosity X-ray pulsars. Conclusions. We demonstrate here with a simple model that Compton upscattering in the radiative shock in the accretion column can produce hard X-ray spectra similar to those seen in the persistent and transient emission of AXPs and SGRs. In particular, one can obtain a high-energy power-law spectrum, with photon-number spectral-index Γ ∼ 1 and a cutoff at 100−200 keV, with a transverse Thomson optical depth of ∼5, which is shown to be typical in AXPs/SGRs.