Mostly from eating live rodents (from a bad source), before or after you got him. They can take a while to multiply. Some kinds of worms they can pick up
also just by being in the "wrong place" on the ground, usually grass; they are left behind by wildlife or loose pets. There's different kinds of "worms". For
that matter, going barefoot can get us in trouble too.
FYI, the worst case of worms I've seen in a snake was in a wild caught "rescued" rattlesnake removed from a golf course & brought to me. (a temporary resident that
went back out after treatment) I hid a light dose of dewormer in the oral cavity of the dead large mouse I fed him, and about a day later, he defecated a pile that put
me off spaghetti for weeks...Countless number of live worms crawling away (& not getting very far on paper towels before they dried up & died anyway). I gave him
multiple dosed meals to clean him out. I know some vets want to use stronger meds to get the job done fast, but IMO it's not always safe for the snake.
It makes sense that internal worms would give some nasty cramps, which fits what your snake is doing, & the deworming med. is safe & easy to give for a snake that's
feeding eagerly. Might be worth a try, or ask your (or any) vet.