One way to avoid cramps and pain is to warm your hands up before playing. Stretch and massage them to help get the blood flowing through and loosen them up.
Then get your guitar and do some hand exercises on it. Start off slow and speed up as you go. Watch your technique to ensure you are not putting any undue pressure on your wrist or fingers. If you feel yourself tightening up, stop playing, relax your hands and start again at a slightly slower tempo.
If I try to start shredding without warming up my hands and arms will tense up and my playing becomes sloppy.