Why does a Mexican jumping bean jump?

Moths will attach an egg to the bean, and the larva will eat its way inside and ingest the inside. If the temperature outside increases, the larva will begin jumping in an attempt to roll the bean (though not technically a “bean”) to a cooler area.

Interestingly, it can survive for months in the bean but will only live a few days once it leaves (as a pupa).

Mexican jumping bean