How do you cure hamstring muscle spasms?

Stretching. Cramps at night are not uncommon. You should consider stretching your muscle groups prior to bed time. In addition you should make sure you are drinking plenty of water. Low potassium may also be an issue. Try eating a banana once a day to increase your potassium level.
Address the cause. Acute spasms in an other wise healthy individual without muscle disease is usually due to acute disturbance in electrolyte balance, usually potassium. Other than manually messaging the muscle, potassium pills, or even better, bananas. Tomatoes also work. Chronic recurrent spasms need further investigation to rule out muscle or neuromuscular disease.