I am probably pretty late to this one, but on macOS you can use caffeinate to prevent the system from sleeping.

I often use -d to keep the display awake:

caffeinate -d

Use man caffeinate for all options.

For years, I used a custom Hammerspoon integration that also displays a nice menubar icon while “caffeinating” (under the hood it uses the same APIs). Since I often use “vanilla” macOS instances, it’s great to know there’s a native alternative.