Harness Shell and Sandbox

The HarnessAgent (adk-harness) runs model-written shell commands through one bash tool. By default the command runs on the host behind a per-command approval; the OS sandbox and the container shell are opt-in, and a strict deployment can refuse to start without them. This page covers the sandboxed and container shells: what they can reach, how a failed command is retried outside them, and what the harness records.

Isolation

ShellIsolationWhere bash runsReported IsolationStatus
Host (default)sh -c on the host, with the user's permissions and networkHost
OsSandbox(OsSandboxConfig)sh -c under Seatbelt (macOS), bubblewrap (Linux) or a restricted token (Windows)OsSandbox { enforcer }
OsSandbox(..) with no working enforcerthe host, as HostDegraded { requested, reason }
Container(ContainerConfig) (feature docker)sh -c in a container per session, the workspace mounted at /workspaceContainer { image }
Container(..) with no reachable Docker daemonthe host, as HostDegraded { requested: "container", reason }
Remote(RemoteShellConfig) (feature remote-shell)sh -c in an environment per session from a SandboxClient, such as an E2B or Daytona microVM or a Modal Sandbox; the host workspace is not mountedRemote { provider, off_host }

The enforcer — for a container, the Docker daemon — is probed when the harness is built, and the sandbox again on every call:

SituationResult
Enforcer unavailable at build, fail_if_unavailable setbuild() fails with harness.sandbox_unavailable
Enforcer unavailable at build, no fail_if_unavailableA warning; the shell is Degraded: it declares and behaves as the host shell, every command needs approval in Ask, and auto_allow_sandboxed has no effect
Enforcer available at build, unavailable at a callThe call is refused with harness.sandbox_unavailable and a harness.sandbox.unavailable record; it never falls back to the host
A session's container cannot be provisioned or started, or lets a protected path be writtenThe same refusal, with the reason in the record

On Windows the sandbox is the restricted-token enforcer (spec 3.2 §10 W5). A restricted token is set when a process is created, so the enforcer starts each command itself, through WindowsEnforcer::spawn_contained, and the bash tool reads its output from pipes. Its probe (WindowsEnforcer::probe_confined) runs cmd.exe /d /c exit 0 under the token: the shell is OsSandbox { enforcer: "restricted-token" } when it succeeds, and Degraded with the reason, or refused under fail_if_unavailable, when it fails. See The Windows sandbox for what it confines.

Turning the sandbox on

use std::sync::Arc;

use adk_harness::{HarnessAgent, HarnessMode, IsolationStatus, OsSandboxConfig, ShellIsolation};
use adk_model::gemini::GeminiModel;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let model = Arc::new(GeminiModel::new(std::env::var("GOOGLE_API_KEY")?, "gemini-3.8-flash")?);
    let harness = HarnessAgent::builder("harness")
        .model(model)
        .workspace(adk_devtools::Workspace::new(".").allow_bash(true))
        .mode(HarnessMode::Ask)
        .shell(ShellIsolation::OsSandbox(OsSandboxConfig::default()))
        .fail_if_unavailable()
        .build()?;
    assert!(matches!(harness.info().isolation, IsolationStatus::OsSandbox { .. }));
    Ok(())
}

OsSandboxConfig fields:

FieldDefaultMeaning
networkfalseAllow all network access when no egress policy applies
egressNoneThe hosts commands may reach, through one egress proxy per command (Proxied network access); narrowed by the run's egress policy, which applies alone when this is None. See Network allowlist
allow_process_spawntrueAllow forking; sh -c forks for every external command
extra_read, extra_writeemptyAdditional read-only and read-write paths
read_toolchainstrueRead-only access to the toolchain directories below
enforcerNoneThe enforcer; None uses adk_sandbox::sandbox::get_enforcer()

What a sandboxed command can reach

SandboxLauncher builds each command with adk_sandbox::sandbox::sandboxed_command as the launcher of the devtools BashTool, which keeps its timeout ceiling, output cap, streaming, empty standard input, new session and process-group kill.

Ask, Auto (read-write)Plan, ReadOnly (read-only)
Workspace rootread-writeread-only
Protected paths that exist (.git, .adk, .skills, .claude, .cargo, AGENTS.md, AGENT.md, CLAUDE.md, MEMORY.md, .envrc, lefthook.yml, lefthook.yaml, and the same names up to four levels below the root)read-onlyread-only
Root-level protected paths that do not exist or are symbolic linksSeatbelt: cannot be created or replaced. bubblewrap: not guarded (see auto_allow_sandboxed)read-only
Per-session scratch directory (HOME, TMPDIR)read-writeread-write
Toolchains (read_toolchains), as listed belowread-onlyread-only
System runtime (/usr, /bin, /System, …, as the enforcer grants it)read-onlyread-only
Anything else, including the real home directory and ~/.sshnonenone
Networkegress and the run's egress policy, else networkthe same

Git. Of a .git directory the sandbox keeps hooks, config and info read-only, the entries that decide which commands git runs, and leaves the index, refs and objects writable, so git add and git commit work inside it. The same holds for a nested repository's .git and for each submodule gitdir under .git/modules.

.gitKept read-only
A directory with hooks, config and info, none a symbolic linkThose three entries
A directory missing one of them, or with one a symbolic linkThe whole directory; git commit needs the unsandboxed retry
A file naming the gitdir (a linked worktree or a submodule checkout)The file. The gitdir lies outside the workspace, so git commit needs the unsandboxed retry

The file tools keep all of .git protected, and rewriting history is reversible through the reflog.

Toolchains. With read_toolchains, a sandboxed command can read exactly these paths:

SourceReadable
CARGO_HOME (default ~/.cargo)bin, registry, git, .package-cache, .package-cache-mutate, .global-cache, and config.toml or config when it holds no token. Never credentials.toml or credentials, which hold registry tokens
RUSTUP_HOME (default ~/.rustup)toolchains, settings.toml, update-hashes
PYENV_ROOT (default ~/.pyenv)bin, libexec, plugins, pyenv.d, shims, versions, version
NVM_DIR (default ~/.nvm)alias, nvm.sh, nvm-exec, and every Node version under versions except its etc, where npm keeps its global npmrc
A PATH directory under the home directoryIts executable files, and the file each executable link in it resolves to. Never the directory's tree, a file named like a credential (.env*, credentials*, .netrc, _netrc, .npmrc, .pypirc, .git-credentials, .pgpass), or anything under ~/.ssh, ~/.aws, ~/.gnupg, ~/.docker, ~/.kube, ~/.azure, ~/.config/gh or ~/.config/gcloud. One inside a toolchain entry above (~/.cargo/bin) adds nothing
A PATH directory outside the home directoryThe directory
System/opt/homebrew, /usr/local; on Linux /usr, /bin, /lib, /lib64 and /etc

A PATH entry that is the home directory, a directory above it, a directory that holds the workspace, or a directory inside the workspace is never granted. A program on a PATH directory under the home directory runs when it is one file; one that loads its own tree from elsewhere in the home directory, such as a pipx virtual environment, needs that tree in extra_read.

Note: cargo stops on a configuration file it can see but not read. Under Seatbelt a ~/.cargo/config.toml that holds a token stays visible and unreadable, so cargo fails inside the sandbox; keep registry tokens in credentials.toml (cargo login). bubblewrap leaves the file out, and cargo runs without it.

On Windows, which does not confine reads (see The Windows sandbox), a PATH directory in the profile is granted whole, since each grant is an ACL change.

PlatformExtra handling
macOSThe active developer directory (xcode-select -p) is readable, DEVELOPER_DIR and SDKROOT are set, and its compiler and git directories come first on PATH. The /usr/bin shims run xcrun, which cannot run under Seatbelt; the tools behind them can, so cargo test links
Linuxbubblewrap starts from an empty root. A toolchain path that is a symbolic link — /bin, /lib, /lib64 on a merged-/usr distribution — is recreated as a link (--symlink) and its target bound, so /bin/sh and the dynamic loader resolve; /dev and /proc are mounted

Environment. The workspace's bash allowlist (Workspace::env_allowlist, default PATH, HOME, LANG, LC_ALL, TMPDIR, TERM, USER, SHELL), with HOME and TMPDIR set to the scratch directory. Agent sockets (SSH_AUTH_SOCK, SSH_AGENT_PID, GPG_AGENT_INFO) and variables named like credentials (TOKEN, SECRET, PASSWORD, PASSWD, API_KEY, CREDENTIAL) never pass in, whatever the allowlist says. With read_toolchains, CARGO_HOME, RUSTUP_HOME, PYENV_ROOT and NVM_DIR point at the real toolchain directories, since HOME moved.

The Windows sandbox

The restricted-token enforcer runs sh -c <script> — the sh the sandbox's PATH finds, from Git for Windows, as the host shell does — under a Low-integrity token whose groups are deny-only (see the sandbox reference). The workspace and the scratch directory are labelled Low, so the command writes there and nowhere else. The command starts in a Job Object, so the bash tool keeps its timeout ceiling, output cap, streaming, empty standard input, the kill of every process the command starts, and the freeze's kill (spec 3.2 §10 W1). It inherits its three standard handles and no other handle of the agent, and none of the three is ever inheritable in the agent's process, so a process the agent starts meanwhile — an MCP server, a hook — cannot hold the command's output open after it exits.

Under the restricted token
Workspace root, scratch directory, extra_writeread-write: RESTRICTED is granted on each and each is labelled Low, once per process; the grant and the label stay on the path
Protected pathswritable: a path inside the workspace inherits its read-write grant and its Low label
Toolchains (read_toolchains)read-only when they lie in your profile (~/.cargo, ~/.rustup, …); program and system directories grant Users read access already and are not rewritten
Your profile and anything else you may readreadable: MSYS2, the runtime of Git for Windows' sh, opens its own signal pipe and shared memory through an ACL that names only you, so you are one of the token's restricting SIDs
Anything else you may write, including paths that grant Everyone or Users write accessnone: an unlabelled path is Medium integrity, which the Low token cannot write; paths already labelled Low, such as %USERPROFILE%\AppData\LocalLow, stay writable
Networknot restricted, whatever network says
Environmentas on the other platforms, with TEMP and TMP also set to the scratch directory; Git for Windows' launcher settings (MSYSTEM, its bin directories first on PATH) when sh is Git's bin\sh.exe
MSYS2, the runtime of sh and of the programs it startsa private copy for each command: msys-2.0.dll, sh.exe, bash.exe and env.exe, copied into an owner-only, Medium-integrity directory under %LOCALAPPDATA%\adk-sandbox\msys2, compared with Git's files before use, first on PATH, and removed when the command's processes end; the command's MSYS2 processes share their object namespace, the mount table among it, with no other process
Your own Git Bash and other MSYS2 programs of an installation on PATH or of sh'skept apart: the command holds your MSYS2 namespace of each such installation at your integrity level with an unconfined cat of it, started before the command, so the command can neither write it nor create it for your next Git Bash to join. An MSYS2 program that a program outside MSYS2 starts itself cannot start: git starts a hook's sh from its own installation, so a commit with a hook fails, with a hint that suggests an approved unsandboxed retry
MSYS2 or Cygwin installations neither on PATH nor sh'snot isolated: a command that starts such an installation's program by its path, while none of yours runs, creates that installation's namespace at Low integrity, and a program of it you start before the command ends joins it

What follows from that:

BehaviourWindowsmacOS, Linux
The bash declaration's network annotation and descriptionnetwork accessnetwork
The bash declaration's reads annotation, IsolationStatus::confines_reads and the status lineunconfined, false, OS sandbox (restricted-token, network not restricted, reads not confined, MSYS2 installations off PATH not isolated); the declaration digest differs from a confining sandbox's, so a standing rule granted under Seatbelt or bubblewrap does not match itconfined, true
The bash declaration's msys2Isolated annotation, harness.bash.begin's msys2Isolated and IsolationStatus::isolates_msys2false: MSYS2 installations neither on PATH nor sh's are not isolatedtrue
Plan modebash is denied: a read-write grant from an earlier command stays in the workspace's ACL, so the sandbox cannot promise a read-only workspacesandboxed commands run read-only without a prompt
Ask and Auto modeevery sandboxed command is askedas the mode table says
auto_allow_sandboxedbuild() fails: the sandbox does not restrict the network, does not confine reads to the workspace and does not isolate the MSYS2 installations off its PATHmacOS: no further condition; Linux: needs every protected path
Hooks with isolation = "inherit"build() fails: a hook needs a command it can spawn and feed; give it isolation = "host"run in the sandbox

The first command of a process grants the workspace, and with read_toolchains the toolchain directories in your profile; Windows applies a grant to everything beneath the path, which takes a while on a large tree. Later commands reuse the grants.

Labels and grants that stay. The token writes only what is labelled Low integrity, so the sandbox labels each read-write path and grants it to RESTRICTED:

PathLabelled LowAfterwards
The workspace root, and what is created beneath itfrom the first sandboxed command on; the label staysany Low-integrity process of the machine may write the workspace
Each extra_write paththe samethe same
The session's scratch directory (HOME, TMPDIR, TEMP, TMP)while the harness runsremoved with its label when the harness is dropped; a killed process leaves it in the temporary directory
Read-only paths (toolchains, extra_read)never; they keep RESTRICTED's read entry—

To take a workspace back, restore its Medium label and remove the grant:

icacls "C:\path\to\workspace" /setintegritylevel "(OI)(CI)M" /T
icacls "C:\path\to\workspace" /remove:g *S-1-5-12 /T

The container shell

With feature docker, ShellIsolation::Container runs each session's commands in its own container. The host workspace is bind-mounted at /workspace, so a file bash writes there is the file read_file reads, and every protected path that exists is mounted read-only over it.

use std::sync::Arc;

use adk_harness::{ContainerConfig, HarnessAgent, HarnessMode, IsolationStatus, ShellIsolation};
use adk_model::gemini::GeminiModel;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let model = Arc::new(GeminiModel::new(std::env::var("GOOGLE_API_KEY")?, "gemini-3.8-flash")?);
    let harness = HarnessAgent::builder("harness")
        .model(model)
        .workspace(adk_devtools::Workspace::new(".").allow_bash(true))
        .mode(HarnessMode::Ask)
        .shell(ShellIsolation::Container(ContainerConfig {
            image: "rust:1.95-slim".to_string(),
            ..ContainerConfig::default()
        }))
        .fail_if_unavailable()
        .build()?;
    assert!(matches!(harness.info().isolation, IsolationStatus::Container { .. }));
    Ok(())
}

ContainerConfig fields:

FieldDefaultMeaning
imageubuntu:22.04 (DEFAULT_CONTAINER_IMAGE)The image of every session's container; it must be present on the daemon
networkfalseDocker's bridge network; false leaves only loopback
extra_read, extra_writeemptyExtra host paths mounted read-only or read-write, as (host path, container path)
userNoneThe user commands run as; None is the current uid:gid, so files the container writes into the workspace belong to you
memory_limit_bytes, cpu_limitNoneContainer resource limits
idle_ttl15 minutesHow long a session's container stays up after its last command
clientNoneA SandboxClient of your own; it must mount the workspace at its root itself and run as a user that may write it (DockerClient::with_user)
LifecycleBehaviour
First command of a sessionSandboxClient::provision and start create the session's container; a probe then tries to write each protected path inside it and refuses the container if one write succeeds
Later commands, later runsThe same container, one per (app, user, session)
Idle for idle_ttlThe container is stopped; the next command provisions a new one
A command times out, a freeze stops it, or its call is cancelledThe container is stopped, which ends the command and everything it started
Harness::closeEvery session's container is stopped

A command runs through SandboxSession::exec_command with the workspace's timeout ceiling, and its output is cut as Output describes once it finishes. Commands in one session's container run one at a time; when one exits, every process it left in the container is killed. The container drops every capability, sets no-new-privileges and limits processes to 512.

Differs from the OS sandboxContainer shell
Unsandboxed retryOff unless allow_unsandboxed_retry(true); when on, it is the same once-only, non-waivable host retry
Hooks with isolation = "inherit"Refused at build with harness.hooks.config; hooks with isolation = "host" run
A goal's until checkRefused, never run on the host in the container's place; the goal ends exhausted
Shell credentials (shell_credential)Refused at build
Plan modeDeny: the container has no read-only workspace mount

The remote shell

With feature remote-shell, ShellIsolation::Remote(RemoteShellConfig::new(client)) runs each session's commands in an environment client provides — E2bClient and DaytonaClient from adk-sandbox, or any other SandboxClient — provisioned from the config's manifest. It shares the container shell's lifecycle, kill switch, audit records and refusals, and caps each call at the wall time left in the run's budget. The environment has its own filesystem, so read_file does not see what bash writes there. An off-host client is governed as the container column below; a client that reports itself on this host, such as LocalUnixClient, as the host shell. See Remote Sandbox Providers.

Modes and approvals

ModeSandboxed bashContainer bashUnsandboxed retry
ReadOnlyDenyDenyDeny
PlanAllow, read-only workspace, under an active enforcer onlyDenyDeny
Ask (default)Approval; Allow with auto_allow_sandboxedApproval; Allow with auto_allow_sandboxedApproval, non-waivable
AutoAllow when sandboxed commands may run unapproved (below); Approval otherwiseAllowApproval, non-waivable

The bash declaration's annotations are {enforcer, profileDigest, network}, where profileDigest covers the enforcer, network, process spawning, toolchain reads and extra paths. A standing rule or a held call is bound to the declaration digest, so a rule granted under one sandbox configuration never applies under another, nor on the host.

auto_allow_sandboxed

Sandboxed commands run without approval in Ask (auto_allow_sandboxed), and in Auto, only when every condition holds:

ConditionChecked
An OS sandbox or a container shell is active (not Host, not Degraded)At build; refused per call if it goes away
network is falseAt build
The enforcer keeps a read-only path inside a read-write path read-only: a conformance script tries to write, create, remove, rename and link beneath one. For a container, each protected path is mounted read-only and a probe in the container tries to write itAt build; for a container, when its container starts
Seatbelt: none further, since its rules name paths: a root-level protected path that does not exist cannot be created, which the conformance script also tries, and one that is a symbolic link cannot be replaced. bubblewrap and a container: every root-level protected path exists and is not a symbolic linkbubblewrap and a container: at build and on every call

While auto_allow_sandboxed is in effect, no host file tool (read_file, glob, grep, write_file, edit_file) runs at the same time as a sandboxed or container command, in any session or team member of the harness: the file tools wait for the command to finish, and a command waits for running file tools. A command cannot rearrange the workspace under a host file tool that is resolving a path in it.

Under Seatbelt a workspace needs none of the protected paths: a command can neither create .envrc nor replace a CLAUDE.md link to AGENTS.md. bubblewrap and a container bind-mount paths, which must exist, so there a protected path that does not exist cannot be protected from creation, and a symbolic link can be replaced: build() fails with harness.auto_allow_sandboxed_unavailable naming each such path, and Auto asks for every sandboxed command. Create the missing ones (.adk, .skills, .claude and .cargo as directories, the rest as files) to turn the setting on. If a protected path disappears later, the next sandboxed command needs approval again.

Network allowlist

Under an egress policy each sandboxed command reaches the network only through its own egress proxy (adk_sandbox::egress_proxy), which admits the hosts the policy names and refuses the rest with 403; see Network Egress Policy. The policy is the run's (Runner::builder().egress_policy, RunConfig::egress_policy) narrowed by the shell's own:

SourceSets
OsSandboxConfig::egressThe shell's policy, in code
.adk/harness.toml [network] allow = ["pypi.org:443", "*.pythonhosted.org:443"]Narrows the shell's policy and turns the OS sandbox on; the project file can only tighten
The run's egress policyNarrows the shell's; applies alone when the shell sets none
BehaviourUnder an egress policy
Each commandProxied network access, with HTTP_PROXY, HTTPS_PROXY and ALL_PROXY pointing at its own proxy; the proxy's records carry the call's id and go to tracing
bash's egress declaration (Tool::egress)Enforced for a sandboxed command; nothing for the unsandboxed retry or a host shell, which a run egress policy refuses
auto_allow_sandboxedRefused at build when OsSandboxConfig::egress is set: an unapproved command could send the workspace to an admitted host
The unsandboxed retryOff when OsSandboxConfig::egress is set; under a run egress policy it declares nothing and is refused
profileDigestCovers the shell's policy, so a standing rule granted under one allowlist does not match another
The Windows restricted tokenCannot place a proxy; bash declares nothing, so a run egress policy refuses it

Note: with auto_allow_sandboxed on and only a run egress policy (none on the shell), sandboxed commands stay unapproved and run through the proxy; set OsSandboxConfig::egress to have them approved one by one.

A failed command and the unsandboxed retry

When a sandboxed command exits non-zero, its result carries a sandbox object:

{
  "exit_code": 1,
  "stderr": "sh: /Users/me/notes.txt: Operation not permitted\n",
  "sandbox": {
    "enforcer": "seatbelt",
    "denialSuspected": true,
    "hint": "The sandbox (seatbelt) may have refused this: writes outside the workspace or to protected paths, and network access, are denied. If the command needs them, retry it once with unsandboxed: true, retry_of: \"call-7\" and a reason; the user must approve the retry."
  }
}

denialSuspected is set when the output contains Operation not permitted, Read-only file system, deny(1), or a name-resolution or unreachable-network error. Every call is recorded in the per-session shell ledger.

The model may then call bash with unsandboxed: true, retry_of and reason. The policy refuses the retry unless retry_of names a failed sandboxed call in the same session with the identical command and no earlier retry, and refuses it outright in ReadOnly and Plan or with allow_unsandboxed_retry(false). Otherwise it is held for a non-waivable approval; the prompt is titled as a host command and shows the model's reason quoted, escaped and capped. The approved retry runs on the host and consumes the failed call, so a replay of it is refused without a prompt.

With the retry off — allow_unsandboxed_retry(false), and always under the personal preset (Personal preset) — bash declares no unsandboxed, retry_of or reason, its hint offers no retry, and a call that sends unsandboxed: true is refused with harness.bash.retry_refused. The declaration digest differs, so a standing rule granted with the retry on does not cover the shell with it off.

Process lifetime and the kill switch

GuaranteeHostSeatbeltbubblewrapContainer
Standard input is /dev/nullyesyesyesno standard input
New session, no controlling terminalsetsidsetsidsetsid and --new-sessionno terminal is attached
Background processes die when the command exitsprocess-group kill; on Windows the command's Job Objectprocess-group kill; on Windows (restricted token) the command's Job Objectthe PID namespace ends with bwrapevery process but the container's own is killed when the command exits
A freeze kills the running commandwithin 250 ms of the pollwithin 250 ms of the pollwithin 250 ms of the pollthe container is stopped within 250 ms of the poll

A process that starts its own session (setsid) leaves the process group and survives the group kill on the host and under Seatbelt; bubblewrap's PID namespace still ends it. On a Windows host no process the command starts can leave its Job Object.

Output

A bash result carries at most 30,000 characters of output (spec 3.1 §7.33 fix 8); the whole output of a longer one is kept for shell_output.

RuleBehaviour
InlineAt most adk_devtools::INLINE_OUTPUT_CHARS (30,000) characters, stdout and stderr together; a stream within half of it keeps all of it and the other stream takes the rest
CutA longer stream keeps the first third and the last two thirds of its share — the first 10,000 and the last 20,000 characters when one stream has it all — around a marker naming the bytes left out and the shell_output call that reads them
KeptThe whole output goes to a file outside the workspace, adk-harness-output-<uid>/<session>/shells/<id>.log in the system's temporary directory (ShellOutputs), private to the user; the result names it as output_id
Disk boundThe file holds at most Workspace::max_output_bytes, 64 MiB by default (adk_devtools::DEFAULT_MAX_OUTPUT_BYTES); memory holds only the start and end of each stream
No cutAn output that fits inline leaves no file
Container shellThe same cut and file, applied once the command finishes
{
  "command": "cargo test",
  "exit_code": 101,
  "stdout": "running 812 tests\n…[5212880 bytes left out; shell_output {\"shell_id\": \"1\"} reads the whole output]\ntest result: FAILED. 811 passed; 1 failed\n",
  "stderr": "",
  "truncated": true,
  "output_id": "1"
}

shell_output { shell_id, tail_lines?, offset?, limit?, pattern? } (class Read) reads at most 30,000 characters of a kept output: its end by default, limit bytes from offset, the last tail_lines lines, or the lines matching the regular expression pattern, numbered. It reads only the calling session's files and never follows a link in their place.

Background shells

bash with run_in_background: true starts the command and returns at once (spec 3.1 §7.29). A dev server, a watcher or a long build keeps running while the agent works.

ToolArgumentsClassResult
bashcommand, run_in_background, description? (a few words shown to the person)The class of the same command in the foreground{ shell_id, status: "running", command, note }; the note tells the model it is told when the shell exits and must not poll
shell_outputshell_id, tail_lines?, offset?, limit?, pattern?Read{ shell_id, status, exit_code?, killed_by?, duration_ms, command, total_bytes, output, … }
shell_killshell_idRead: allowed in every mode, since it only removes an effect{ shell_id, status, killed, duration_ms, exit_code? }
RuleBehaviour
DecisionExactly the foreground decision: the same class, the same ShellPrefix rules and the same isolation digest; a prompt's title ends with , in the background
Declarationrun_in_background and description join the declaration, so a standing rule granted before them is stale once (harness.rule.stale)
SpawnThe same launcher, environment and empty standard input as a foreground call; the output goes to the shell's file from its first byte
DuplicatesA command identical to one still running in the session returns that shell, with already_running: true
Foreground timeoutA call that reaches its timeout moves to the background under the same decision instead of being killed; the result carries moved_to_background: true, timeout_secs and the shell_id. A session already running its most shells kills it as before
CompletionA shell that ends is named in the reminder of every request until shell_output reads it or shell_kill removes it: shell 3 ("cargo watch") exited 101 after 4m12s; last line: "error[E0308]: mismatched types"; shell_output 3. The line is data: quoted, cut and with control characters escaped; the policy never reads it
SessionsA session lists, reads and stops only its own shells
Shell ledgerA background command is recorded when it ends, with its exit code, so a failed sandboxed one can be retried unsandboxed
Action ledgerThe call's result is the started shell, so a re-issued call is answered from its record and never starts a second server
PeopleOutput streams to the console through emit_progress as a foreground call's does; /shells lists each shell with its id, state, age and command, and /shells kill N stops one

BackgroundShellConfig sets the limits:

Limitunattended() (the default)attended() (the adk-rust REPL)
Running shells per session (max_running)88
Output that kills a shell (max_output_bytes)64 MiB64 MiB
Lifetime (with_lifetime, at most 2 h)30 minutesnone
use std::sync::Arc;
use std::time::Duration;

use adk_harness::{BackgroundShellConfig, HarnessAgent, HarnessMode};
use adk_model::gemini::GeminiModel;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let model = Arc::new(GeminiModel::new(std::env::var("GOOGLE_API_KEY")?, "gemini-3.8-flash")?);
    let harness = HarnessAgent::builder("harness")
        .model(model)
        .workspace(adk_devtools::Workspace::new(".").allow_bash(true))
        .mode(HarnessMode::Ask)
        .background_shells(
            BackgroundShellConfig::unattended().with_lifetime(Duration::from_secs(2 * 60 * 60)),
        )
        .build()?;
    assert!(harness.runtime().toolset().tool_names().iter().any(|name| name == "shell_kill"));
    Ok(())
}
Shell endsHow
It exitsIts exit code and last line are recorded; the process group is killed as a foreground call's is
A freezeThe shell's watcher polls the run's kill switch every 250 ms and kills it
Its output or lifetime limitThe watcher kills it and records why (killed_by: output_limit, lifetime)
shell_kill, /shells kill NKilled and removed from the reminder
Session endHarness::end_session_shells kills the session's shells
Harness::close, the process exitingEvery shell is killed; the adk-rust REPL closes the harness when it exits
A crashEach shell's pid and start time, and the harness process's, are kept in a ShellPidRegistry (harness.db in adk-rust); the next start kills the process group of every shell whose harness process is gone, unless its pid now names a process started later
IsolationWhat background shells suit
HostServers, watchers and long builds, with the same approval as the command in the foreground
OS sandboxBuilds, tests and watchers. bubblewrap unshares the network per call, so a server started there is unreachable from later commands, and Seatbelt binds no port without network: a server needs the host, through an approved unsandboxed retry
OS sandbox with auto_allow_sandboxedNone: a sandboxed command in the background is refused with harness.shell.background_gated, since no host file tool may run beside an unapproved sandboxed command (I26), and a timed-out one is killed
Container shellNone yet: it declares no run_in_background, and a timed-out command is killed

Audit records

ActionFields (ext)
harness.bash.begin (write-ahead, args_digest, payload_ref = digest of the command)functionCallId, enforcer, profileDigest, network, reads, workspaceAccess, envKeys, retryOf, goalCheck, background
harness.bash.end (outcome, payload_ref = digest of the result)functionCallId, enforcer, exitCode, durationMs, timedOut, killedByFreeze, truncated, denialSuspected, retryOf, shellId (a call that started a background shell)
harness.shell.startedfunctionCallId, shellId, pid
harness.shell.endedfunctionCallId, shellId, exitCode, durationMs, killedBy (requested, freeze, output_limit, lifetime, session_end, close), truncated
harness.bash.retry_unsandboxedfunctionCallId, retryOf, failedEnforcer, failureDigest, decision, source (policy when requested, tool when consumed)
harness.sandbox.unavailablefunctionCallId, requested, error

Residual risks

RiskStatus
A process that calls setsid outlives the call on the host and under SeatbeltDocumented; bubblewrap ends it with the PID namespace
A background shell's group is killed after a crash only at the next start, and only where the OS reports process start times (macOS, Linux)Documented; on Windows the Job Object ends the shell with the harness process
A protected name that does not exist below the root (a new nested AGENTS.md, .envrc or .git) can be created by a sandboxed commandRoot-level names are guarded under Seatbelt and gate unapproved commands under bubblewrap; nested files are listed, never inlined, by the instruction loader
On a case-sensitive file system a differently cased protected name (agents.md) is a different fileFile tools match protected names case-folded; the sandbox protects names that exist
An admitted host receives whatever a command sends itUnapproved sandboxed commands need network: false and no egress policy
Git runs code from places the sandbox leaves writable: a core.hooksPath inside the workspace (Husky's .husky), or a repository a command creates and registers as a submodule through the writable index, whose own config git honours when it recurses into itDocumented; the sandbox protects the gitdirs that exist when the command starts
A protected name created inside the container after it started is not mounted read-onlyThe container's protected mounts are fixed when it starts; root-level names must exist for auto_allow_sandboxed, and the next container mounts new ones
A container from a client of your own keeps a background process a command leaves, since the harness cannot tell that its sessions are isolated from the hostContainers the harness builds end them after each command; stop them in your client's exec_command
A sandboxed command can read the workspace's secret files (.env)grep and glob skip them and read_file refuses them; bash needs approval unless auto_allow_sandboxed is on
A sandboxed command can read what a tool keeps inside a granted toolchain entry, an executable file it keeps in a PATH directory, and a PATH directory outside the home directoryToolchain homes are granted entry by entry and credential files are left out; keep secrets out of PATH directories

Red-team scenarios

examples/harness_redteam runs a scripted attacker against the 3.0 CodingAgent, the harness with its sandbox unavailable, and the harness under the platform enforcer, and prints one row per scenario: poisoned nested AGENTS.md, project configuration granting bash, .mcp.json spawn, git-hook persistence, background survivors, retry replay, digest drift, a lying readOnlyHint, control characters hiding a command, an ~/.ssh read, a network canary and a .env grep canary. cargo run -- --live runs a sandboxed cargo test, a denied write with its hint and approved retry, and the degraded path on OpenAI, Anthropic and Gemini.

Harness Shell and Sandbox - ADK-Rust 문서 | ADK-Rust