Context. Supernova remnants (SNRs) are thought to be the main source of Galactic cosmic rays (CRs) up to the "knee" in CR spectrum. During the evolution of a SNR, the bulk of the CRs are confined inside the SNR shell. The highest-energy particles leave the system continuously, while the remaining adiabatically cooled particles are released when the SNR has expanded sufficiently and decelerated so that the magnetic field at the shock is no longer able to confine them. Particles escaping from the parent system may interact with nearby molecular clouds, producing γ-rays in the process via pion decay. The soft gamma-ray spectra observed for a number of SNRs interacting with molecular clouds, however, challenge current theories of non-linear particle acceleration that predict harder spectra. Aims. We study how the spectrum of escaped particles depends on the time-dependent acceleration history in both Type Ia and corecollapse SNRs, as well as on different assumptions about the diffusion coefficient in the vicinity of the SNR. Methods. We solve the CR transport equation in a test-particle approach combined with numerical simulations of SNR evolution. Results. We extend our method for calculating the CR acceleration in SNRs to trace the escaped particles in a large volume around SNRs. We calculate the evolution of the spectra of CRs that have escaped from a SNR into a molecular cloud or dense shell for two diffusion models. We find a strong confinement of CRs in a close region around the SNR, and a strong dilution effect for CRs that were able to propagate out as far as a few SNR radii.