A device known as a magnetic field projector had the ability to create a magnetic field.
These magnetic field projectors were positioned around the perimeter of a Star Destroyer's hangar, and they produced a magnetic field. This field served to shield the bay's interior from the vacuum that existed in space.