AI agents · OpenClaw · self-hosting · automation

Quick Answer

Safest Way to Run Autonomous Coding Agents Overnight

Published:

The short answer

The safest overnight setup is a disposable machine, a closed network, no standing credentials and a pull request as the only output. Nobody is watching at 3 a.m., so every protection has to be enforced by the environment, not by an approval prompt you will not see. As of November 8, 2026, in order of safety:

  1. A cloud agent in a per-task VM that ends in a PR — Cursor Cloud Agents, Codex cloud, Claude Code on the web, GitHub Copilot cloud agent.
  2. A local container (Docker or a VM) with the repo mounted and an egress allowlist — when code cannot leave your network.
  3. Claude Code’s sandbox on your own machine, hardened — acceptable with credential paths denied and a domain allowlist.
  4. An agent on your laptop with permissions bypassed — do not do this unattended.

The options compared

SetupIsolationNetwork defaultCredentials exposureOutputOvernight verdict
Cursor Cloud AgentsPer-agent Firecracker microVM in a separate AWS accountConfigurable network access modesRepo access inherited from the triggering user, never widened; secrets configured per teamBranch + PR for human reviewSafest turnkey option
Codex cloudOpenAI-hosted container per taskInternet off during the agent phase; setup scripts have internetOnly what you put in the environmentDiff / PRSafest default network posture
Docker container you runContainer boundary; only mounted paths visibleWhatever you configure (use an allowlisting proxy)Only what you pass inCommits to a branchBest when code must stay on-prem
Claude Code sandbox (local)OS-enforced limits on shell commands onlyProxy with empty allowed-domain listReads ~/.ssh and ~/.aws by default unless denied; env vars inheritedLocal commitsOK only once hardened
Local agent, bypass permissionsNoneOpenEverything your user can reachAnythingNever unattended

Facts from each vendor’s documentation on November 8, 2026.

Step 1: Put the agent on a machine you can throw away

A VM or container that dies after the run limits the blast radius of a bad command or a malicious dependency to that box. Cursor documents that each Cloud Agent gets its own Firecracker-based microVM, that the VMs run in an AWS account separate from the rest of Cursor’s production systems, and that VMs are hibernated and deleted on lifecycle timers after the run. Locally, the equivalent is one container per task with only the repository mounted. Our Docker vs process vs remote sandbox guide covers the trade-offs, and best AI agent sandboxes ranks hosted runtimes.

Step 2: Close the network, then open only what the build needs

This is the control that matters most unattended. OpenAI’s Codex cloud blocks internet access during the agent phase by default, while setup scripts can still install dependencies. If you enable access, Codex offers a “Common dependencies” allowlist preset (package registries and source hosts) and lets you restrict methods to GET, HEAD and OPTIONS, which stops the agent from POSTing your code anywhere. Claude Code’s sandbox routes traffic through a local proxy whose allowed domains start empty. Whatever runtime you use, the rule is the same: default deny, allow registries, block everything else.

Step 3: Remove standing credentials

Claude Code’s documentation is explicit that, by default, sandboxed commands can read credential files such as ~/.ssh and ~/.aws/credentials and inherit environment variables. Before an overnight run, deny those paths (filesystem.denyRead), scrub the environment, and give the agent only a short-lived, repository-scoped token. Cloud agents help here: Cursor’s agents reach code through the Cursor GitHub or GitLab app, with access limited to what the triggering user can already see. Our guide to giving agents credentials without leaking them has the patterns.

Step 4: Make a pull request the only way out

An agent that can merge or deploy can do damage before you wake up. Let it push to a branch and open a PR; Cursor’s Cloud Agents open pull requests for a human to review before anything merges. Protect main with required reviews and CI so even a compromised agent token cannot land code.

Step 5: Cap spend and keep a log

Set a budget limit with your model provider or agent platform, cap the number of turns or the wall-clock time, and keep the full command log. A loop that retries a failing test for eight hours is the most common overnight failure, and it is a billing problem rather than a security one.

Know what the sandbox does not cover

Claude Code’s sandbox wraps shell commands only. Claude’s built-in file and web tools, MCP servers and hooks run outside it, and on native Windows commands run unsandboxed (use WSL2). If an MCP server has write access to production, the sandbox does not help. Audit every MCP server and hook before leaving an agent alone with them, as described in our permission modes guide.

A pre-flight checklist

  • Fresh VM or container; repository mounted, home directory not.
  • Egress default deny; registries allowlisted; write methods blocked where supported.
  • No SSH keys, cloud credentials or production tokens in reach.
  • Branch-only push; main protected; PR as the deliverable.
  • Spend cap and time limit set; command log retained.
  • MCP servers and hooks reviewed, read-only where possible.

Last verified: November 8, 2026.

Sources