A snake crawling on horizontal surfaces between two parallel walls exhibits a unique wave-like shape, which is different from the normal shape of a snake crawling without constraints. We propose that this intriguing system is analogous to a buckled beam under two lateral constraints. A new theoretical model of beam buckling, which is verified by numerical simulation, is firstly developed to account for the special boundary conditions. Under this theoretical model, the effect of geometrical parameters on the deformation shape, such as the distance between walls, length of the snake and radius of the snake, is examined. The buckling beam model is then applied to explain qualitatively the wave-like shape of the snake.