The Drosophila larva is extensively used as model species in experiments where behavior is recorded via tracking equipment and evaluated via population-level metrics. Although larva locomotion neuromechanics have been studied in detail, no comprehensive model has been proposed for realistic simulations of foraging experiments directly comparable to tracked recordings. Here we present a virtual larva for simulating autonomous behavior, fitting empirical observations of spatial and temporal kinematics. We propose a trilayer behavior-based control architecture for larva foraging, allowing to accommodate increasingly complex behaviors. At the basic level, forward crawling and lateral bending are generated via coupled, interfering oscillatory processes under the control of an intermittency module, alternating between crawling bouts and pauses. Next, navigation in olfactory environments is achieved via active sensing and topdown modulation of bending dynamics by concentration changes. Finally, adaptation at the highest level entails associative learning. We could accurately reproduce behavioral experiments on autonomous free exploration, chemotaxis, and odor preference testing. Interindividual variability is preserved across virtual larva populations allowing for single animal and population studies. Our model is ideally suited to interface with neural circuit models of sensation, memory formation and retrieval, and spatial navigation.