If you absolutely want to prevent a Mac from not only going to sleep, but restarting for any reason at all (say, to install important security updates, which are usually forced on the user with no choice), there aren't many good ways. The only thing I've found that really works reliably is to open MS Word, create a new document, add some random characters to it, and then leave without ever saving. Word will prevent the OS from doing anything that would cause you to lose that unsaved document. I'm sure the MS engineers dug deep into the kernel to find something foolproof. It's a bit annoying that Apple doesn't give you a little switch like that which you could toggle to say "don't restart for any reason at all".

The windows equivalent to this is an unsaved text file in notepad.

PowerToys[0] has a utility for that. It stays in the corner of the taskbar.

[0] https://github.com/microsoft/PowerToys