The simulation of charged and/or strongly polar solutes represents a challenge for standard molecular-dynamics techniques. The use of periodic boundary conditions (PBCs) leads to artifacts due to the interaction between two replicas in the presence of the long-range Coulomb forces. A way to avoid these problems is the use of nonperiodic boundary conditions. A possible realization is to consider a finite system, a sphere, embedded in a reaction field described by the method of the images. In the present work the modified image approximation has been implemented in a molecular-dynamics code and optimized for the use of two standard solvents, water and acetonitrile. The methodology has then been applied to investigate the conformational changes in water-solvated alanine dipeptide. The free-energy surface calculated with this method is comparable to that obtained with PBC.