Nozzle jumps off the bed when using Marlin Mesh Bed Leveling
None of the answers address your question to solve it! The only sensible contribution comes from a comment of @TomvanderZanden.



For the sensor to stay within the limits of the bed (considering the offset of the sensor and the size of the hotend carriage) you need to define where the sensor (plus carriage) may go to (to keep the sensor also on the bed, you also need to define the sensor limits). The suggested constants are important in defining the size of the bed and the build volume, but changing them does in fact do not solve your problem. Your problem is that you need to address where the sensor may probe within that specified volume i.e. the sensor probing area.

I use ABL (Auto Bel Leveling) on my Anet A8 using a left-front mounted sensor at position (x = -26 mm; y = -40 mm seen from the nozzle center). In order to have the sensor on the bed area without running into the limits of the carriage, you have to calculate (yourself!) what the dimension of the auto bed leveling area is. This is because the sensor is off set from the nozzle. If the sensor reaches for the whole bed, you need extra space on the axis. To explain this, if your sensor is at the left front, as in my case, the amount of extra space you have left on the right side of the X carriage will determine how far the carriage may go and thus limits the right probe position. If there is no extra space on the carriage (the safest assumption) you just need to add the sensor offset to the maximum bed size (what the nozzle can reach). E.g. my probe X offset is -26 mm. The maximum probe distance is therefore -26 mm + 220 mm = 194 mm.

This means that you need to set the following constants (amongst the settings to enable ABL; the probe and the type of leveling...) in the configuration.h of your Marlin Firmware installation:

#define X_PROBE_OFFSET_FROM_EXTRUDER -26   // X offset: -left  +right  [of the nozzle]
#define Y_PROBE_OFFSET_FROM_EXTRUDER -40   // Y offset: -front +behind [the nozzle]

// Set the boundaries for probing (where the probe can reach).
#define LEFT_PROBE_BED_POSITION (0 + 10)         // 10
#define RIGHT_PROBE_BED_POSITION (220 - 26 - 10) // 184
#define BACK_PROBE_BED_POSITION (220 - 40 - 10)  // 170
#define FRONT_PROBE_BED_POSITION (0 + 10)        // 10


Furthermore the settings you do mention need to be:

// The size of the print bed
#define X_BED_SIZE 220
#define Y_BED_SIZE 220

// Travel limits (mm) after homing, corresponding to endstop positions.
#define X_MIN_POS -33 // Distance from end switch to X = 0 of origin
#define Y_MIN_POS -10 // Distance from end switch to Y = 0 of origin
#define Z_MIN_POS 0
#define X_MAX_POS X_BED_SIZE
#define Y_MAX_POS Y_BED_SIZE
#define Z_MAX_POS 240


The -33 and the -10  define how much the nozzle needs to travel from the endstop position to the print origin! This is not necessary to change when using ABL with a sensor (unless you are using a different print head carriage with a different center of the nozzle). Why these values are -33 and -10 (or values close to this; e.g. for my printer they are -36 and -8) is explained in this answer.