Magnetically driven quantum heat engine