Most coding agent sessions start the same way: someone opens a terminal on their laptop, starts Claude Code or Codex, gives it a task, and watches. That works until the laptop goes to sleep, the battery runs out, the power goes, the office Wi-Fi drops, or the VPN reconnects. Then the agent stops in the middle of whatever it was doing, and someone has to work out what state it left the repository in.
For one developer this is an annoyance. For a team that has started handing agents longer tasks (a dependency upgrade across a monorepo, a migration, a large test-fixing pass), it is the main reason those tasks fail. This post is about separating "my connection to the agent" from "the agent's work", so the first can drop without killing the second.
What actually breaks
It helps to be precise, because the fixes are different.
- The process dies with the machine. If the agent runs on the laptop, sleep or a power cut stops it. Nothing on the laptop can fix that.
- The process dies with the terminal. If the agent runs on a remote machine but in the foreground of an SSH session, a dropped connection can take it down with the session.
- The task is lost even if the process survives. An agent that was halfway through edits, with nothing committed, leaves a working tree nobody can read with confidence.
- The person cannot see what happened. Without a way to reconnect to the same session or read its output, people restart the task from scratch.
Move the agent off the laptop
The structural fix is to run the agent on its own machine that does not sleep when your laptop does. With Sandscale that is a workspace: a persistent cloud computer per agent, with its own disk. The docs say an agent running in a workspace keeps working when your laptop is closed, and that the repository, branch, installed tools and the agent's session are still there the next time you open it.
Setting one up with the Sandscale CLI (1.4.1):
sandscale workspace templates-list
sandscale workspace create --name agent-upgrade --template-id TEMPLATE_ID
sandscale workspace ssh agent-upgrade
create asks before it runs and answers with the workspace id. Inside, clone the repository and sign the agent in, the way you would on a new laptop. The disk is kept, so you do this once. If the CLI on the workspace needs to sign in, sandscale login uses a code you approve on your phone or laptop, because there is no browser there.
Keep the agent out of the SSH session's lifetime
Running the agent on a workspace removes the laptop from the picture. The SSH session is still a thread that can break. Start the agent inside a terminal multiplexer such as tmux or screen on the workspace (install it in the template, or once on the workspace, if it is not there), so the session lives on the workspace and your SSH connection only attaches to it:
tmux new -s agent
# start Claude Code or Codex here, give it the task, then detach with Ctrl+B D
When the connection drops, reconnect and reattach:
sandscale workspace ssh agent-upgrade
tmux attach -t agent
workspace ssh uses the system ssh through Sandscale with a short-lived certificate, so a reconnect after a network change is a new connection, not a stale one.
Check on it without attaching
Sometimes you only want to know whether the agent is still going, from a phone hotspot or a slow connection. Two commands help:
sandscale workspace get --ws-id WORKSPACE_ID
sandscale workspace exec --ws-id WORKSPACE_ID --command '["sh", "-c", "cd ~/app && git log --oneline -5 && git status --short"]'
get shows the workspace's state and its agent status. exec runs one command as you and answers with its exit code and output, and asks before it runs. Only the workspace's owner can run commands, with their own sign-in, and every run is in the audit log without its command text.
Make the task survive, not only the process
A process that survives a disconnect is half the fix. The other half is how you write the task, usually in the AGENTS.md the agent reads:
## Long tasks
- Work on a branch named agent/<task>.
- Commit after each step that passes the focused tests, with a message that says
what the step was. Push after each commit.
- Keep a short progress note in NOTES.md: done, in progress, next.
- If a command fails twice for reasons outside the code (network, registry),
stop and write that in NOTES.md instead of retrying forever.
Small pushed commits mean that even if everything else goes wrong, the work so far is on the remote, readable by anyone on the team.
What to check before you rely on it
-
The idle timeout. A workspace stops after it has been idle for a while: the organization's default is 30 minutes, and you can set it per workspace (at least 300 seconds, within your organization's maximum) with
sandscale workspace update --ws-id WORKSPACE_ID --idle-timeout-seconds N. Before leaving a long unattended run, try a short one: start the agent, disconnect, and confirm withworkspace getthat the workspace is still running a while later. -
The time to live.
--ttl-secondscaps how long the workspace runs after it starts. Set it to fit the task with some margin; your organization's lifecycle policy can shorten it. -
Usage. A running workspace counts toward your plan's hours whether the agent is working or waiting. Stop it when the task is done:
sandscale workspace stop --ws-id WORKSPACE_ID. The disk is kept. - Your own connection for review. Reviewing still needs a connection. It just no longer has to be up for the whole run.
The result
The laptop becomes what it should be for this kind of work: a window. Close it, lose power, change networks, and the agent carries on, on its own machine. When you are back, you reattach, read NOTES.md and the commits, and decide what happens next. When a team runs several agents this way, one per machine, nobody's laptop is the bottleneck any more.
For the cost side of running agents on laptops, see what it costs a team when coding agents run on laptops. For runs that should start and stop on a schedule, see overnight coding agent runs.
Originally published on the Sandscale blog.
Top comments (0)