How to keep an AI agent running 24/7 on a Mac

Stop the Mac from sleeping, keep tasks running after you disconnect, restart them after a crash, check progress remotely, and the settings to change first.

Updated Dec 2, 2026

How to keep an AI agent running 24/7 on a Mac

01Why agents stop

Starting an agent is easy. Keeping it from stopping halfway is the hard part. The usual causes:

  • The Mac went to sleep.
  • The task ran directly in a terminal window, so closing the window or losing the SSH connection ended it.
  • The program crashed and nothing restarted it.
  • macOS installed an update and restarted.
  • A permission prompt appeared and the task sat waiting for a click.
  • Logs and caches filled the disk.

Here is how to deal with each of them, in order.

02Stop the Mac from sleeping

A NexMini Mac is already set never to sleep and to start up again automatically after a power cut, so you do not need to change its power settings. On your own Mac, open System Settings → Energy and turn on “Prevent automatic sleeping when the display is off”.

To keep the Mac awake only while one task runs, put caffeinate in front of the command, for example caffeinate -i ./run-agent.sh.

A NexMini Mac logs in to your account automatically when it starts, including after a restart. Programs that were running before the restart do not come back on their own; use launchd, described below, to start them automatically.

03Keep tasks running after you disconnect

Run the task inside tmux, a “background session”: it keeps going after you close the window or disconnect, and you can reattach later. Homebrew is already installed on a NexMini Mac, so you can install it without sudo:

brew install tmux

  1. Run tmux new -s agent to create a session called agent, and start your agent inside it.
  2. Press Ctrl+B, then D, to leave the session. The task keeps running in the background.
  3. Next time you connect, run tmux attach -t agent to get back to it.

04Bring it back after a crash or restart

tmux does not help when the program crashes or the machine restarts. To restart it automatically and start it at login, use launchd, which is built into macOS:

  1. Create a .plist file in ~/Library/LaunchAgents/, for example com.example.agent.plist.
  2. Put the command to run in ProgramArguments, add RunAtLoad (start at login) and KeepAlive (restart when it exits), and use StandardOutPath and StandardErrorPath to write output to log files.
  3. Run launchctl load ~/Library/LaunchAgents/com.example.agent.plist to load it. After editing the plist, run launchctl unload and then load again.

Let the agent exit when something goes wrong and launchd will start it again. That is more reliable than piling retry logic into the program.

05Change these settings first

  • Turn off automatic macOS update installs: System Settings → General → Software Update, and under Automatic Updates turn off installing macOS updates, so the Mac does not restart in the middle of the night. Install updates yourself when it suits you.
  • Grant permissions up front: if your agent needs Accessibility or Screen Recording, turn them on in System Settings → Privacy & Security before you start, so no prompt is left waiting for a click.
  • On a NexMini Mac your account is a standard account, so both of these need an administrator. Just contact us and we will do them for you.
  • Watch disk space: logs and caches keep growing, so clean them up regularly. Many programs fail outright when the disk is full.
  • Change the Mac account’s initial password to your own.

06Check progress remotely

  • See the desktop: connect with DeskIn or NetEase UU Remote and watch what the agent is doing. Both have phone apps too, handy for a quick look while you are out.
  • Command line only: connect over SSH (with Tailscale), reattach with tmux attach, or follow the log with tail -f.
  • Let it tell you: have the agent send a message when it finishes or fails, for example to Telegram, Slack or email, so you do not have to keep watching.

07Do not forget backups

NexMini does not back up your data. Push the code and data your agent produces to a Git repository or sync it elsewhere regularly. When your rental ends, your Mac account and all its files are deleted and no data is kept.