I know Prusa slicer and Cura both warn when the print is too big for the printer. AFAIK, all slicers will prevent you from generating gcode files that go beyond the print limits of the machine- that's why they want to know how big the bed is and the maximum Z dimension when you configure the printer.
If you're trying to run gcode generated for a different machine on your printer all bets are off. For that I'd say either don't do it or write a simple processor that reads the coordinates of all the moves in the gcode file and looks for any that are beyond the limits of your printer. Movement beyond axis limits is only one problem. There could be all sorts of other problems buried in the gcode, such as print speed or acceleration being too high for the printer.
If you're trying to detect layer shifting while printing, you'll need some limit switches that detect movement beyond axis limits because in a layer shifted print, the controller thinks everything is fine, even if it sends the extruder and/or bed beyond the limits of an axis. Keep in mind that layers can shift without moving beyond axis limits, so those added switches may not do any good. Some Markforged printers detect layer shifting by rehoming X and Y axes after every layer. If the extruder and/or bed travels the correct distance to reach home, the print isn't shifted and it's OK to print the next layer. I ran an experiment with this idea when I installed optical endstops in my corexy printer. The problem with rehoming every layer is it adds significantly to the total print time even as it minimizes wasted filament. You could rehome every 10th layer- that would reduce time spent rehoming but allow some waste of filament if the print was shifted.
My printer doesn't shift, ever, because I use conservative settings and maintain the mechanism. If you're experiencing frequent layer shifts, maybe there's a hardware problem that needs to be addressed, or it's time to adjust your expectations of the printer's performance limits and reconfigure accordingly.