The supernova remnant (SNR) HESS J1731-347 displays strong nonthermal TeV γ-ray and X-ray emission, thus the object is presently accelerating particles to very high energies. A distinctive feature of this young SNR is the nearby (~30 pc in projection) extended source HESS J1729-345, which is currently unidentified but is in spatial projection coinciding with known molecular clouds (MC). We model the SNR evolution to explore whether the TeV emission from HESS J1729-345 can be explained as emission from runaway hadronic cosmic rays (CRs) that are illuminating these MCs. The observational data of HESS J1729-345 and HESS J1731-347 can be reproduced using core-collapse SN models for HESS J1731-347. Starting with different progenitor stars and their presupernova environment, we model potential SNR evolution histories along with the CR acceleration in the SNR and the diffusion of the CRs. A simplified three-dimensional structure of the MCs is introduced based on 12CO data of that region, adopting a distance of 3.2 kpc to the source. A Monte Carlo based diffusion model for the escaping CRs is developed to deal with the inhomogeneous environment. The fast SNR forward shock speed, as implied from the X-ray data, can easily be explained when employing scenarios with progenitor star masses between 20 M⊙ and 25 M⊙, where the SNR shock is still expanding inside the main-sequence (MS) bubble at present time. The TeV spectrum of HESS J1729-345 is satisfactorily fitted by the emission from the highest energy CRs that have escaped the SNR, using a standard Galactic CR diffusion coefficient in the interclump medium. The TeV image of HESS J1729-345 can be explained with a reasonable three-dimensional structure of MCs. The TeV emission from the SNR itself is dominated by leptonic emission in this model. We also explore scenarios where the shock is starting to encounter the dense MS progenitor wind bubble shell. The escaping hadronic CR hypothesis for the γ-ray emission of HESS J1729-345 can still hold,but even in this case our model cannot easily account for the TeV emission from HESS J1731-347 in a hadronic scenario.