Welcome to these Forums Dipto!
A very good question for an 8th grader - keep asking good questions and you will get some good answers - hopefully...
Magnetic fields certainly do "work in space" and the Earth's magnetic field plays all sorts of interesting effects with the Solar Wind.
All forms of mass, energy and stress are sources of the gravitational field.
However you would be very hard put to create a large enough magnetic field to cause a measurable effect on space-time.
Having said that there are collapsed stars with very strong magnetic fields called
Magnetars and their magnetic fields will strongly affect the gravitational field.
Garth