The current study investigates the body–environment interaction and exploits the passive viscoelastic properties of the body to perform undulatory locomotion. The investigations are carried out using a mathematical model based on a dry frictional environment, and the results are compared with the performance obtained using a physical model. The physical robot is a wheel-based modular system with flexible joints moving on different substrates. The influence of the spatial distribution of body stiffness on speed performance is also investigated. Our results suggest that the environment affects the performance of undulatory locomotion based on the distribution of body stiffness. While stiffness may vary with the environment, we have established a qualitative constitutive law that holds across environments. Specifically, we expect the stiffness distribution to exhibit either an ascending–descending or an ascending–plateau pattern along the length of the object, from head to tail. Furthermore, undulatory locomotion showed sensitivity to contact mechanics: solid–solid or solid–viscoelastic contact produced different locomotion kinematics. Our results elucidate how terrestrial limbless animals achieve undulatory locomotion performance by exploiting the passive properties of the environment and the body. Application of the results obtained may lead to better performing long-segmented robots that exploit the suitability of passive body dynamics and the properties of the environment in which they need to move.