Using negative feedback. start with a sensor coil that detect the magnetic field, then feed the signal to a high gain inverting amp. The output of the amp drive the coil to generate an equal and opposite magnetic field to cancel the original field. basically it's a closed loop control circuit.
The electronic circuit is relatively easy to design, getting the mechanical dimension of those coil to really cancel the field might be difficult and also the placement of the sensor coil.