Skip to content

Remote Agent Host Lifecycle: Sandbox Profiles and Cleanup

Coordinate sleep holds, sandbox profiles, standalone Dev Containers, and worktree cleanup on remote Agent Hosts under host and harness limits.

Remote agent host lifecycle management applies when you run long-lived VS Code Agent Host sessions on machines you operate, within explicit host, harness, and maturity boundaries. VS Code 1.148 (released November 25, 2026) adds four host-level controls: idle-sleep prevention (Preview), remote sandbox profiles (Experimental), standalone Dev Containers with agent handoff (Experimental), and remote worktree cleanup (VS Code 1.148). Three of the four are Preview or Experimental. Their boundaries differ: idle-sleep settings apply on the host rather than the client (remote agent sessions), and the Copilot terminal sandbox toggle does not configure Claude or Codex sessions (agent sandboxing).

The remote host lifecycle problem

Moving an agent loop onto another machine solves window-disconnect durability, as covered in Remote Agent Host Sessions over SSH and Dev Tunnels. Once sessions run unattended across SSH hosts, WSL distributions, and Dev Tunnels, four host-local bottlenecks replace editor crashes: idle sleep interrupts active turns, remote hosts need different sandbox rules across build servers and shared machines, ad-hoc tasks lack a .devcontainer/devcontainer.json, and stale worktrees fill remote disks (VS Code 1.148; Agent Host architecture).

VS Code 1.148 also lowers Agent Host overhead. Chat responses begin 30% faster on average than in the previous Stable version, placing chat start times within ~5% of the old harness (VS Code 1.148). The Rust-based VS Code CLI (used to bootstrap Remote SSH connections, some WSL connections, and remote agent hosts from the Agents window) is about 40% smaller, with slight variations per platform (VS Code 1.148).

graph TD
    A[Configure host sleep hold] --> B[Assign host sandbox profile]
    B --> C[Start session or container]
    C --> D[Agent runs unattended]
    D --> E[Reclaim remote worktrees]
    D --> F[Delete standalone container]

Four lifecycle layers

Layer 1: Host idle-sleep holds

Set sessions.keepAwakeWhileWorking (Preview) on the host machine, not the client, so a supported Agent Host keeps its machine awake during active turns, including after you close the window (VS Code 1.148; remote agent sessions).

It defaults to whenPluggedIn and accepts three modes (AI settings):

  • whenPluggedIn: prevents idle sleep when the host reports external power.
  • always: prevents idle sleep during agent work, including on battery.
  • never: allows idle sleep during agent work.

The hold ends two minutes after the last running chat stops, allows the display to turn off, and does not inhibit explicit sleep (AI settings). Linux desktop cannot detect external power, so whenPluggedIn allows idle sleep there (AI settings).

Layer 2: Host-scoped sandbox profiles

Enable chat.agent.sandbox.profiles.enabled (Experimental) to save named sets of agent sandbox settings and assign one to each remote agent host (VS Code 1.148). Manage profiles via Sandbox: Manage Sandbox Profiles and assign them in Remote Environments. The assignment is stored on the remote, so every device connecting to it uses that profile, while organization sandbox policies still apply and the remote needs an up-to-date VS Code Server (VS Code 1.148).

Profiles configure the Copilot terminal sandbox (see Dual-Boundary Sandboxing). Turning sandboxing on does not block outbound network access by default; set chat.agent.sandbox.network.allowNetwork to false or list chat.agent.sandbox.network.allowedDomains explicitly (agent sandboxing). Host OS prerequisites apply where commands run: macOS 15 or later; glibc-based Linux or WSL2 with bubblewrap 0.5.0+, slirp4netns, util-linux 2.35+, and compatible iptables; or Windows 11 with BaseContainer and required updates (Experimental). Alpine Linux, musl distributions, and WSL1 are unsupported (agent sandboxing).

Layer 3: On-demand containers

Enable chat.agentHost.devContainer.environments.enabled (Experimental, default false, alongside chat.agentHost.devContainer.enabled and chat.remoteAgentHostsEnabled) to create standalone Ubuntu Dev Containers with an Agent Host inside and workspace files in a Docker volume, without writing a container configuration (VS Code 1.148; AI settings). Create them locally or on a connected SSH host, WSL distribution, or Dev Tunnel running Docker with its CLI on PATH (Agents window).

Also enable chat.agentHost.devContainer.handoff.enabled (Experimental, default false) so an agent can request a standalone container on its host and continue the task in a new linked session there (VS Code 1.148; Agents window). You review and approve the container host and new session before startup. Handoff passes a task summary rather than full conversation history, does not copy project files into the new workspace, and lets the new session report back when done (VS Code 1.148; Agents window).

Standalone and project-configured Dev Containers follow different lifecycle rules (Agents window):

Lifecycle rule Project-configured Standalone
Config file .devcontainer/devcontainer.json or .devcontainer.json None (Ubuntu container and Docker volume)
Idle shutdown Stops after 5 minutes (chat.agentHost.devContainer.idleTimeout, default 300 s) No idle timeout; persists independently
Session end Marking sessions as done or deleting them can remove it Disconnecting or marking done keeps files
Removal Session cleanup or rebuild Manual Delete in Remote Environments; deletes volumes

Dev Container sessions edit the container workspace directly and do not support New Worktree (Agents window).

Layer 4: Remote worktree cleanup

Run Chat: Open Worktree Cleanup from the Command Palette, Chat view menu, or Agents window to reclaim disk space from inactive agent-managed worktrees on connected remote hosts that support cleanup (VS Code 1.148; worktrees). Rows and confirmations name the owning host so identical paths on different machines stay distinct, while disconnected or unsupported hosts are unavailable (VS Code 1.148).

Cleanup marks listed sessions done while protecting worktrees used by other sessions or chats. It commits nonignored changes, including untracked files, to their branches and schedules the worktree folders for removal. Branches and session history remain so restoring a session re-creates its worktree, while ignored files inside removed worktrees are deleted permanently (worktrees).

Automatic cleanup suggestions (chat.agentSessions.sessionStorageCleanupSuggestion.enabled, Experimental, default true) appear in the Agents window at 5 GiB of inactive worktrees, 20 qualifying worktrees, or low local disk space, and do not appear in the regular editor window or monitor remote free disk space (AI settings). If the connection drops during cleanup, reconnect and refresh to verify completion because unknown size estimates and pending or failed entries do not confirm removal (worktrees).

Triggers and constraints

Control Maturity and default Trigger Scope limit
sessions.keepAwakeWhileWorking Preview (whenPluggedIn) Active turn Host machine only; Linux desktop allows idle sleep on whenPluggedIn (AI settings)
chat.agent.sandbox.profiles.enabled Experimental Manual assign Stored on remote; Copilot only; org overrides (VS Code 1.148; sandboxing)
chat.agentHost.devContainer.environments.enabled Experimental (false) Manual create Needs Docker; persists without idle stop (Agents window)
chat.agentHost.devContainer.handoff.enabled Experimental (false) Agent + approval Task summary only; no file copy (Agents window)
Chat: Open Worktree Cleanup Shipped 1.148; suggestions Experimental (true) Manual confirm Remote cleanup needs connected, supported hosts; deletes ignored files (worktrees)

Multi-tool coverage

These controls are specific to VS Code 1.148 and its Agent Host. The Agent Host contains adapters for Copilot, Claude, and Codex (Agent Host architecture). The Sandboxing for terminal toggle applies to the Copilot harness and does not configure sandboxing for Claude or Codex sessions, and neither harness can enforce Copilot's enterprise-managed sandbox settings (agent sandboxing). For committed .devcontainer/ setups across Claude Code and Copilot CLI, see Dev Containers for AI Coding Agents. For worktree isolation and Claude Code's ExitWorktree guard, see Worktree Isolation and Confirming Before an Agent Removes a Worktree With Unsaved Work.

Why it works

Moving the agent loop into a dedicated Agent Host process relocates session ownership, file edits, and shell execution onto the execution host (Agent Host architecture). This extends Session Harness Sandbox Separation into host operations. Clients disconnect during unattended turns and connect to hosts with different trust tiers and storage pools, so placing sleep holds, sandbox profiles, container volumes, and worktree cleanup at the host boundary matches each control to the machine that owns the process and disk.

When this backfires

  • Linux desktop hosts on whenPluggedIn. Linux desktop cannot detect external power, so whenPluggedIn allows idle sleep there. Set always on the host to prevent idle sleep during agent work (AI settings).
  • Multi-harness fleets expecting uniform sandboxing. Copilot sandbox profiles do not configure Claude or Codex sessions, and Copilot sandboxing leaves outbound network open by default (agent sandboxing).
  • Sandboxing inside a Dev Container on a shared host. When sandboxing is on for a new Dev Container session, VS Code adds --security-opt seccomp=unconfined, --security-opt apparmor=unconfined, --security-opt systempaths=unconfined, and --device /dev/net/tun (agent sandboxing). VS Code cautions: "These Docker options relax the container's isolation from the host. Commands that the agent runs still run inside the sandbox, but other processes in the container don't gain that protection automatically" (agent sandboxing).
  • Untracked standalone Dev Containers. They skip idle shutdown and session cleanup, and deleting one permanently removes its Docker volumes and workspace files (Agents window).
  • Sweeping remote worktrees without saving ignored files or monitoring remote disks externally. Cleanup deletes gitignored files permanently, and suggestions ignore remote free disk space (worktrees; AI settings).
  • Updating remote servers mid-run or depending on editor tools. Server updates restart the host and interrupt active sessions (remote agent sessions), and client-contributed tools vanish on disconnect (Agent Host architecture; Multi-Client Session Attachment).
  • Persistent host upkeep is unnecessary when you do not need local host resources. Cloud sessions use provider-managed infrastructure where the service manages environment availability and lifetime instead of requiring you to keep your own remote machine and host process running (Agent Host architecture).

Example

Prepare a Linux desktop remote host for unattended VS Code 1.148 sessions by setting sessions.keepAwakeWhileWorking to always on the host machine and enabling the experimental sandbox-profile and standalone Dev Container settings (VS Code 1.148; AI settings):

// Remote Linux desktop host settings.json
{
  "sessions.keepAwakeWhileWorking": "always"
}
// VS Code Agents window settings.json
{
  "chat.agent.sandbox.profiles.enabled": true,
  "chat.agentHost.devContainer.enabled": true,
  "chat.agentHost.devContainer.environments.enabled": true,
  "chat.agentHost.devContainer.handoff.enabled": true
}

Next, create host-specific rules with Sandbox: Manage Sandbox Profiles, assign the profile to the host in Remote Environments, and periodically sweep inactive remote worktrees with Chat: Open Worktree Cleanup after copying out needed gitignored files (VS Code 1.148; worktrees).

Key Takeaways

  • Set sessions.keepAwakeWhileWorking on the host machine, and choose always on Linux desktop hosts because whenPluggedIn permits idle sleep without external-power detection.
  • Assign sandbox profiles per remote host so every client inherits the same policy, and restrict outbound network settings explicitly because Copilot sandboxing permits outbound traffic by default.
  • Do not rely on Copilot sandbox profiles for Claude or Codex sessions, and weigh the relaxed Docker options (seccomp=unconfined, apparmor=unconfined, systempaths=unconfined, /dev/net/tun) before running sandboxing inside a Dev Container.
  • Audit standalone Dev Containers manually: they ignore the 5-minute idle timeout, deleting one removes its Docker volumes and workspace files, and handoff copies neither full history nor project files.
  • Verify the owning host and back up gitignored files before running Chat: Open Worktree Cleanup, because ignored files are deleted permanently and suggestions do not monitor remote free disk space.