Free-piston engines are under investigation by a number of research groups worldwide, as an alternative to conventional technology in applications such as electric and hydraulic power generation. The piston dynamics of the freepiston engine differ significantly from those of conventional engines, and this may influence in-cylinder gas motion, combustion and emissions formation. Due to the complex interaction between mechanics and thermodynamics, the modelling of free-piston engines is not straight-forward. This paper presents a novel approach to the modelling of free-piston engines through the introduction of solution-dependent mesh motion in an engine CFD code. The particular features of free-piston engines are discussed, and the model for engine dynamics implemented in the CFD code is described. Finally, the coupled solver is demonstrated through the modelling of a spark ignited free-piston engine generator.