Cosmic rays that escape their acceleration site interact with the ambient medium and produce gamma rays as the result of inelastic proton-proton collisions. The detection of such diffuse emission may reveal the presence of an accelerator of cosmic rays, and also constrain the cosmic ray diffusion coefficient in its vicinity. Preliminary results in this direction have been obtained in the last years from studies of the gamma-ray emission from molecular clouds located in the vicinity of supernova remnants, which are the prime candidate for cosmic ray production. Hints have been found for a significant suppression of the diffusion coefficient with respect to the average one in the Galaxy. However, most of these studies rely on the assumption of isotropic diffusion, which may not be very well justified. Here, we extend this study to the case in which cosmic rays that escape an accelerator diffuse preferentially along the magnetic field lines. As a first approximation, we further assume that particles are strongly magnetized and that their transport perpendicular to the magnetic field is mainly due to the wandering of the field lines. The resulting spatial distribution of runaway cosmic rays around the accelerator is, in this case, strongly anisotropic. An application of the model to the case of the supernova remnant W28 demonstrates how the estimates of the diffusion coefficient from gamma-ray observations strongly depend on the assumptions made on the isotropy (or anisotropy) of diffusion. For higher levels of anisotropy of the diffusion, larger values of the diffusion coefficient are found to provide a good fit to data. Thus, detailed models for the propagation of cosmic rays are needed in order to interpret in a correct way the gamma-ray observations.