Snakes evolved from lizards only about 150 million years ago, during the Jurassic Period. This is during the time of the dinosaurs, about the same time that the first birds evolved from small dinosaurs. Like birds and mammals, though, snakes really began to take over after most of the dinosaurs died about 95 million years ago, at the end of the Cretaceous period. Snakes are a late-arriving kind of reptile.
The earliest snakes still had legs, but gradually snakes evolved to lose their legs and arrange their body parts differently so they could do different things.
A snake eating a mouse
No snake eats anything but meat, and because the main kind of meat that was available as snakes were evolving was small mammals, mostly what snakes eat is small mammals like mice and guinea pigs. So snakes evolved to go into the holes in the ground where small mammals like mice lived, and eat them.