To limit cramps: warm-ups, stretching.
Warm up gently, quietly for at least 20 minutes. After your workout, stretch, stretch the muscles that worked the most, practice breathing movements that oxygenate the blood better.
If you exercise, hydrate yourself!
It is essential to drink a lot during a physical exercise, whatever the sport level. You must drink regularly before, throughout the exercise and afterwards of course. Do not wait until you are thirsty.
Sweating causes loss of water and mineral salts (sweat is salty) and losses need to be compensated. It is essential to be well hydrated.
In commerce, there are "powders" to dissolve in water, or solutions ready with minerals, sugar, vitamins but they are expensive. The water of Vichy, the Saint-Yorre, for example are quite salty, to prefer for the intensive sports of endurance. Some fruits are very popular among athletes: bananas rich in potassium and slow sugars, dried fruits that are fairly caloric and take up little space have plenty of mineral salts, citrus fruits are rich in vitamin C.
Athletes each have their "thing" to get cramps going; in their pharmacy case they have almost all their products containing magnesium, potassium, homeopathic products, phytotherapeutics ...