Overnight coding agent runs: one workspace per agent, started by you, stopped and woken on a schedule
Some agent work does not need anyone watching: a dependency bump across packages, a test suite to get green, a refactor with a clear spec. Teams that use Claude Code or Codex often want to hand that work to agents at the end of the day and review the result in the morning. On a laptop, that means leaving the laptop open, awake and online all night, running one agent at a time. With one cloud…
In the world of coding, some tasks can be left to run overnight without any human supervision. These tasks typically involve dependency updates, testing, or refactoring with a clear specification. When using tools like Claude Code or Codex, teams often want to delegate such work to agents at the end of the day and review the results in the morning.
To set up this automated workflow, Sandscale workspaces can be utilized. Each agent requires its own workspace, which includes its own checkout, dependencies, and disk space. This ensures that runs do not interfere with one another.
The process begins by creating a workspace for each task using the `sandscale workspace create` command, specifying a unique name and template ID for each workspace. The CLI then returns an ID for each workspace, which will be used later in the setup process.
Once the workspaces are created, connect to each one via SSH and clone the repository. This step only needs to be done once per workspace. Sign in to the agent as you would on a new laptop, allowing the workspace to retain its disk space for future use.
To start the agent inside a tmux session, which keeps the run going even when disconnected, use the `sandscale workspace ssh` command followed by `tmux new -s run`. Within this tmux session, start the agent non-interactively with the appropriate task flags, such as `claude -p` or `codex exec`.
Upon completion, the agent should commit its changes to a new branch and push them to the repository. This ensures that the result is not dependent on the specific machine being used. Detach from the tmux session using `Ctrl-b d` and repeat the process for the next workspace.
To prevent the workspace from running indefinitely, set a time to live (TTL) using the `sandscale workspace update` command with the `--ttl-seconds` flag. This cap limits the maximum runtime in seconds since the workspace started, respecting the organization's lifecycle policy. A shorter TTL is recommended for each task to avoid unnecessary resource consumption.
In the morning, bring each workspace back to life using the `sandscale workspace update` command with the `--autostart-schedule` flag. This cron expression, set to run at a specific time (e.g., 08:30 on weekdays), will automatically start the workspace with the agent's checkout and tmux session history on disk.
Before relying on the scheduled start, ensure that the workspace is functioning correctly by using the `sandscale workspace get` command. Verify that the idle timeout setting and session length per plan are appropriate for your specific needs. If your plan's included hours are exhausted, the workspace will stop, and the disk space will be preserved. Lastly, confirm that any required approvals are in place before starting the overnight runs.
By implementing one workspace per agent, each run remains separate, allowing for easier management and avoiding potential conflicts. In the morning, teams can review a set of branches instead of dealing with a tangled mess of code. To create your first workspace, consult the Sandscale Quickstart and workspace guide.
Rewritten by urgent.news; may contain errors — check the original.
Source: dev.to