Running launchd agent not preventing macbook from sleeping I have an agent/daemon that runs a backup script (I use restic) at 4:05am on a StartCalendarInterval. My understanding is that if a launchd agent is running, that should prevent osx from sleeping. Is that wrong?

I can see that my script partially worked as a snapshot was created in the repository, but when I went to check the snapshot, the repo had a lock on it which indicates to me something happened mid-run.

Here is my plist file for the agent.

&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt;
&lt;plist version="1.0"&gt;
        &lt;dict&gt;
                &lt;key&gt;Label&lt;/key&gt;
                &lt;string&gt;backup.restic.username&lt;/string&gt;
                &lt;key&gt;ProgramArguments&lt;/key&gt;
                &lt;array&gt;
                        &lt;string&gt;/Users/username/Documents/scripts/backup.sh&lt;/string&gt;
                &lt;/array&gt;
                &lt;key&gt;StartCalendarInterval&lt;/key&gt;
                &lt;dict&gt;
                        &lt;key&gt;Minute&lt;/key&gt;
                        &lt;integer&gt;5&lt;/integer&gt;
                        &lt;key&gt;Hour&lt;/key&gt;
                        &lt;integer&gt;4&lt;/integer&gt;
                &lt;/dict&gt;
        &lt;/dict&gt;
&lt;/plist&gt;


Is there something I can add there to prevent sleeping? I will say the macbook wasn't plugged in and was at 35% battery when I woke up.
@nohillside gave me what to lookup. Updated to use caffeinate to prevent disk and system from sleeping.

&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt;
&lt;plist version="1.0"&gt;
        &lt;dict&gt;
                &lt;key&gt;Label&lt;/key&gt;
                &lt;string&gt;backup.restic.username&lt;/string&gt;
                &lt;key&gt;Program&lt;/key&gt;
                &lt;string&gt;/usr/bin/caffeinate&lt;/string&gt;
                &lt;key&gt;ProgramArguments&lt;/key&gt;
                &lt;array&gt;
                        &lt;string&gt;-im&lt;/string&gt;
                        &lt;string&gt;/Users/username/Documents/scripts/backup.sh&lt;/string&gt;
                &lt;/array&gt;
                &lt;key&gt;StartCalendarInterval&lt;/key&gt;
                &lt;dict&gt;
                        &lt;key&gt;Minute&lt;/key&gt;
                        &lt;integer&gt;5&lt;/integer&gt;
                        &lt;key&gt;Hour&lt;/key&gt;
                        &lt;integer&gt;4&lt;/integer&gt;
                &lt;/dict&gt;
        &lt;/dict&gt;
&lt;/plist&gt;