Hot or cold for back spasm?

Both! Initially cold to calm down the inflammation from the initial injury and then heat helps the muscle itself to relax. Ice is usually maximum benefit for the first 72 hours only. Try to eliminate the cause of the back spasm and avoid it in future. Avoid prolonged sitting, including working on a computer and driving. Avoid heavy lifting. Muscle relaxants and a chiropractor may be helpful.
Alternate. Heat will feel good and will relax the muscles. Ice will take down swelling.