Mexican jumping beans are hollow seed capsules that contain a tiny immature insect. It is the movement of the larva inside the seed capsule that causes the bean to jump.
A moth known to science as Cydia deshaisiana lays its eggs on the capsules of several species of Mexican shrub. The larva then eats its way inside and lives in the capsule until it matures. High temperatures cause the larva to wiggle around inside the capsule. In its natural habitat, this is achieved by direct sunlight and the hot desert climate. The movement is theorized to be an adaptation to protect the larva from cooking inside the capsule.
The plants called Mexican jumping beans are not closely related to common bean plants. In fact, the plants used by the moth belong to a group called spurges.