This describes how to stop your Mac from sleeping without modifying the system settings.
Introduction
By default the Mac is set to sleep after a relatively short time. Also, some workplaces impose a short time period before the computer sleeps. There are two reasons you might want to maintain this setting quite small: it saves power by sleeping the computer, and it locks the screen to avoid unauthorised access when the user leaves it.
Note that in some managed environments you cannot change this, but if you do what to this time can be set by launching "System Settings", then clicking "Lock Screen", then changing the times available to make the sleep delay more useful.
Another approach involves temporarily telling the computer to stay awake longer for specific reasons, especially when the Mac is doing something that takes a longer time without the user doing anything, such as when viewing a movie, displaying a presentation, etc.
There are various friendly apps to do this, such as the free "Caffeinate" which just allows the user to set a time the computer should stay awake for. After the time period is complete, the usual sleep settings take effect again. If you need more features, such as allowing sleep after a process completes, you can use a more advanced app, like "Amphetamine" but that isn't free.
Using the command
Finally, you can stop your Mac sleeping using a built-in command from terminal. To do this, run Terminal (it's usually in the "Utilities" folder which is inside the "Applications", then type this: "caffeinate" (without the quotes) and press return.
You won't see much change but the Mac should then not sleep and you can use it normally (you must leave Terminal running, but you can hide it).
To terminate the command, just go back to Terminal and type control-C (hold down the control key and press C) and quite from Terminal.