Muscular spasms resulting in pain are typically treated with a combination of benzodiazepines with muscle relaxant properties and anti-inflammatories. This combination would only really be suitable for acute treatment, if this is a recurring problem then a topical antiinflammatory gel such as diclofenac may be of some use or perhaps heat patches which work by increasing blood flow to the area in question thereby alleviating the cause of the pain if spasm is involved.
If you spend long periods idle then stretching or moving around intermittently to avoid repetitive strain injury would be advantageous.