this section covers more than just compass sensors. Originally, autopilots relied on just a fluxgate heading sensor to provide magnetic heading information.
The current generation of autopilots, at very least, use what is known as a "rate compass". This is a more advanced fluxgate compass, combined with a solid state gyro sensor included which measure rate of turn as well.
Some include heave, pitch and roll measurement to provide further functionality.
Satellite compasses also feature, these use multiple GPS antennas and clever calculations to provide heading data without any risk of magnetic interference. These devices are an ideal solution for steel boats, or boats with lots of equipment that may cause stray magnetic fields.