We analyze the lateral undulatory motion of a natural or artificial snake or other slender organism that "swims" on land by propagating retrograde flexural waves. The governing equations for the planar lateral undulation of a thin filament that interacts frictionally with its environment lead to an incomplete system. Closures accounting for the forces generated by the internal muscles and the interaction of the filament with its environment lead to a nonlinear boundary value problem, which we solve using a combination of analytical and numerical methods. We find that the primary determinant of the shape of the organism is its interaction with the external environment, whereas the speed of the organism is determined primarily by the internal muscular forces, consistent with prior qualitative observations. Our model also allows us to pose and solve a variety of optimization problems such as those associated with maximum speed and mechanical efficiency, thus defining the performance envelope of this mode of locomotion.