Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 127 additions & 0 deletions docs/ADRs/0146-sandbox-environment-contract-manifest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
---
Comment thread
jflowers marked this conversation as resolved.
Resolved
Comment thread
jflowers marked this conversation as resolved.
Resolved
Comment thread
jflowers marked this conversation as resolved.
Resolved
Comment thread
jflowers marked this conversation as resolved.
Resolved
Comment thread
jflowers marked this conversation as resolved.
Resolved
Comment thread
jflowers marked this conversation as resolved.
Resolved
Comment thread
jflowers marked this conversation as resolved.
Resolved
Comment thread
jflowers marked this conversation as resolved.
Resolved
Comment thread
jflowers marked this conversation as resolved.
Resolved
Comment thread
jflowers marked this conversation as resolved.
Resolved
title: "146. Sandbox environment contract manifest"
status: Accepted
relates_to:
- agent-infrastructure
- security-threat-model
topics:
- sandbox
- runtime
- security
- drift
---

# 146. Sandbox environment contract manifest

Date: 2026-10-21

## Status

Accepted

## Context

The sandbox environment surface — what the runner injects into the sandbox and
reserves from harness override — was hand-synced in three descriptions, none
machine-checked: the sync note on the `reservedSandboxKeys` map in
`internal/cli/run.go`,
the agents repo's `SANDBOX_RUNTIME_VARS` allowlist in
Comment thread
jflowers marked this conversation as resolved.
Resolved
`scripts/skill-env-reachability-test.sh`, and per-runtime `EnvExports()` in
prose only. The drift was realized in
[fullsend-ai/agents#1677](https://github.com/fullsend-ai/agents/issues/1677):
a skill migrating `CLAUDE_CONFIG_DIR` to a proposed `FULLSEND_SKILLS_DIR`
passed the agents repo's reachability gate because the same PR edited the
allowlist — no released runner exports it, and a bot reviewer, not CI, caught
it. Content repos cannot verify at PR time that env vars their skills
reference are exported by any released runner — a drift-control gap in the
[threat model's](../problems/security-threat-model.md) ranked priorities.

The lockstep with the fleet harnesses fullsend loads
([ADR 0058](0058-agent-registration.md)) is enforced only by tribal
knowledge; the topology this needs — released tag at PR time via
[ADR 0038](0038-universal-harness-access.md)'s pinned-URL mechanism,
`main` nightly
([ADR 0139](0139-agent-functional-test-suite-lives-in-agents-repo.md)) —
already exists for functional tests. The proposed `FULLSEND_SKILLS_DIR`
([fullsend-ai/agents#1672](https://github.com/fullsend-ai/agents/issues/1672))
is a follow-up to close the remaining drift surface.

## Options

- **Hand-maintained manifest** — rejected: it recreates the drift
(#1677 passed review the same way).
- **Generated bespoke JSON document** — rejected in review: every other
contract under `docs/normative/` is JSON Schema, and a schema lets any
consumer validate with stock tooling instead of parsing a custom format.
- **Behavior-level golden over `bootstrapEnv`** — strongest check, but
needs fixtures for every emission gate; hardening follow-up.

## Decision

Publish the sandbox environment contract as generated, committed JSON
Schemas (Draft 2020-12) under
[`docs/normative/sandbox-env/v1/`](../normative/sandbox-env/v1/README.md):

- [`harness-env.schema.json`](../normative/sandbox-env/v1/harness-env.schema.json)
validates a harness YAML's `env.sandbox` blocks: no key may be a name
the runner reserves.
- [`env-references.schema.json`](../normative/sandbox-env/v1/env-references.schema.json)
validates that code running under a runtime reads only variables the
contract makes reachable there, and carries the full inventory —
always, conditional (with gates), per-runtime, harness-delivered,
reserved, deprecated — in its `$defs`.

A build-time collector generates the schemas by running every code path
that injects environment variables into the sandbox: the
`.env` emission in `bootstrapEnv` (`internal/cli/run.go`), the
per-iteration env, trace-ID injection, the security-hook env, each
production runtime's `EnvExports()` and launch-command exports, the
`fullsend agent new` Vertex scaffold, and the effective reserved-key set
after the init-time merges. Commands are replayed in a scratch workspace
and parsed for real `export` bindings, and each runtime's declared launch
exports are checked against its built launch commands, so the contract
cannot disagree with the code that builds the environment. An always-on
golden test byte-compares the committed schemas against collector output
(`-update` regenerates); a companion runtime-enumeration test fails when
a runtime is newly registered without a contract decision.

The schemas are fetchable at any tag via raw.githubusercontent.com
(tag-pinned URLs complement the commit-SHA + integrity-hash mechanism of
[ADR 0038](0038-universal-harness-access.md) for read-only contract
data that does not execute). The `v1` path and the tag identify the
version. Consumers validate against the latest released tag at PR time
and `main` nightly, following the
[ADR 0139](0139-agent-functional-test-suite-lives-in-agents-repo.md)
bridge. `fullsend lint` keeps checking reserved keys in-process; the
schemas serve repos that validate without running the fullsend binary.

Scope is the sandbox only. The environment of host-side pre-scripts,
post-scripts, and validation scripts (`childScriptEnv`,
`validationScriptEnv`) is a different surface — the runner's own
environment plus `env.runner` — and is out of scope here.

## Consequences

- Adding, changing, or reserving a runner env var requires a same-PR
schema regeneration, visible in the diff.
- Content repos gain a fail-closed gate: a failed or unparseable schema
fetch fails the check rather than skipping it.
- The [ADR 0058](0058-agent-registration.md) transitional lockstep between
runner and fleet harnesses becomes verifiable instead of tribal knowledge.
- The schemas are derived contract data — no runtime cost or behavior
change.
- Harness-delivered variables are not runner guarantees: their
provenance is the stock scaffold and may lag the fleet's
`gcp-vertex.env`.
- A future per-version harness JSON Schema
([ADR 0127](0127-harness-schema-versioning-and-field-types.md)
follow-up) can `$ref` the env definitions here instead of restating them.

## Forge scope

The schemas are forge-agnostic: they describe the variables the runner
injects into the sandbox regardless of which forge hosts the repository.
The fetch URL uses raw.githubusercontent.com because fullsend is hosted on
GitHub; a GitLab or Forgejo deployment would use the equivalent raw-file
endpoint. Consumer validation logic (parse, fail closed) is
forge-independent.
15 changes: 13 additions & 2 deletions docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,13 @@ each target repository's **`.fullsend/`** directory

- What is the right isolation level — process, container, microVM, or separate cluster? (See [agent-infrastructure.md](problems/agent-infrastructure.md) and [security-threat-model.md](problems/security-threat-model.md).)
- ~~How granular is network regulation? Allowlist of endpoints, or coarser controls?~~ Decided in [ADR 0065](ADRs/0065-provider-backed-policy-composition.md): network access is granted through provider profiles with per-endpoint allowlists.
- Does the sandbox provide a pre-built environment (tools, language runtimes, repo clones), or does the agent set up its own workspace within the sandbox?
- Does the sandbox provide a pre-built environment (tools, language
runtimes, repo clones), or does the agent set up its own workspace
within the sandbox? (The environment-variable dimension is now a
published, generated contract —
[ADR 0146](ADRs/0146-sandbox-environment-contract-manifest.md),
[contract](normative/sandbox-env/v1/README.md); tools, runtimes,
and workspace setup remain open.)
- ~~Is the sandbox the same for all agent roles, or does each role get a differently-scoped sandbox?~~ Decided in [ADR 0020](ADRs/0020-composable-single-responsibility-agents-with-individual-sandboxes.md): each agent gets its own sandbox with policies designed for its responsibility.

**Decided:**
Expand Down Expand Up @@ -133,7 +139,12 @@ repo baseline and overrides)
sub-maps replaces `runner_env` and manual `.env` files. The runner generates
the sandbox `.env` file from `env.sandbox` at bootstrap. `runner_env` is
deprecated ([ADR 0055](ADRs/0055-unified-env-var-delivery.md), amending
[ADR 0024](ADRs/0024-harness-definitions.md)).
[ADR 0024](ADRs/0024-harness-definitions.md)). What the runner itself
injects — which env vars every sandbox receives, which arrive per runtime
via `EnvExports()`, and which keys are reserved from harness override — is
published as generated, tag-pinned JSON Schemas enforced by an always-on
golden test ([ADR 0146](ADRs/0146-sandbox-environment-contract-manifest.md);
[contract](normative/sandbox-env/v1/README.md)).
- Runner secrets on GitHub (interim until external secret manager support
or #6359 settles the long-term route, then kept as the fallback for
workflows without GitHub OIDC or WIF; integrations fullsend owns keep their
Expand Down
5 changes: 5 additions & 0 deletions docs/cli/run.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,11 @@ on every runtime (claude, pi, codex, opencode):
| `FULLSEND_ITERATION_DEADLINE` | Unix time (seconds) at which the running iteration is killed |
| `TRACEPARENT` | W3C trace context of this iteration's **agent** span (not the run-root span that pre/post scripts receive). Runtimes use it to join fullsend traces. An inbound unsampled parent (`-00`) is preserved so runtime export stays suppressed. Empty when telemetry produced no valid span context. Reserved: an `env.sandbox` entry with this name is dropped. |

The full inventory of what the runner injects into the sandbox — these names
included — and of the keys it reserves from `env.sandbox` override is
published as the generated [sandbox environment
contract](../normative/sandbox-env/v1/README.md).

**Example.** A probe that shows both, and what a kill looks like. The agent prints the variables
with its own clock, then sleeps past the budget:

Expand Down
15 changes: 15 additions & 0 deletions docs/contributing/runtime-implementation.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ content that must be updated whenever a runtime is added or renamed.
if the runtime is user-selectable).
- [x] `internal/config/config_test.go` — update any assertion on
`ValidRuntimes()` to include the new name.
Comment thread
jflowers marked this conversation as resolved.
Resolved
Comment thread
jflowers marked this conversation as resolved.
Resolved
- [x] `internal/cli/env_manifest_collector_test.go` and
`internal/cli/env_manifest_golden_test.go` — the runtime's `EnvExports()`
names must land in the generated
[sandbox environment contract](../normative/sandbox-env/v1/README.md);
Comment thread
jflowers marked this conversation as resolved.
Resolved
Comment thread
jflowers marked this conversation as resolved.
Resolved
Comment thread
jflowers marked this conversation as resolved.
Resolved
registering a runtime without a contract decision fails
`TestEnvManifestRuntimeEnumeration`, and `TestEnvManifestGolden` pins the
committed schemas (regenerate with
`go test ./internal/cli -run TestEnvManifestGolden -update`).

**CLI:**

Expand Down Expand Up @@ -212,6 +220,7 @@ Harness `security.fail_mode` controls whether critical findings **block** the ru
| `runtime.GatewayRouteRuntime` | Optional — for a runtime that carries the inference gateway route (ADR 0137). `PrepareGatewayRun(sandboxName, GatewayRun)` receives the resolved `inference.gateway` block, the committed `models_file` bytes and the gateway base URL before Bootstrap, and `ClearGatewayRun` releases it at the end of the run. `GatewayCredentialSeed() CredentialSeed` names the route's placeholder env key, `sh` seed fragment and credential file, which the runner re-runs after each token refresh, independently of the OpenAI route's seed (`OpenAIRouteSeed`). pi, codex and Claude Code implement it. pi and Claude Code read the placeholder before the agent-writable `.env` and own the route's environment after it. pi, and Claude Code in the `oidc` mode, seed the placeholder into a token file with the shared `gatewayTokenSeed`, and codex with its own seed; both write through `orderedSeedWrite`; Claude Code in the `api-key` mode writes no token file: it captures the placeholder in a readonly shell variable and exports it as `ANTHROPIC_AUTH_TOKEN` after `.env` (as `ANTHROPIC_API_KEY`, with `ANTHROPIC_AUTH_TOKEN` cleared, when the block sets `messages_auth_header: x-api-key`). Claude Code ignores the block's model list, and its `GatewayRun` registration also feeds its `--settings` document: the route pins and the helper, merged with the hooks and passed inline on gateway runs, never as the uploaded `hooks.json` path. The runner refuses a `gateway/` model on a runtime that does not implement it |

| `runtime.ProviderResolver` | Optional — multi-provider runtimes return the OTEL GenAI serving-endpoint identity for the model the run will call (`ProviderFor`). The runner writes it as both `gen_ai.system` and `gen_ai.provider.name`. Single-vendor runtimes omit this and `GenAISystemFor` falls back to `System()` |
| `runtime.LaunchEnvExporter` | Optional — a runtime whose launch command exports environment variables beyond `EnvExports()` lists those bare names via `LaunchEnvExports()` (flat list, including provider-conditional names). The sandbox env contract collector unions them into that runtime's `runtime_<name>` set (`docs/normative/sandbox-env/v1/`), and `TestLaunchEnvExportsMatchLaunchCommands` fails unless the list equals what the runtime's built launch commands export beyond `EnvExports()` — add a variant to `launchCommandVariants` for any new launch branch. claude, codex, opencode, and pi implement it; runtimes whose launch commands export nothing new omit it |

**Per-iteration cleanup contract.** When a validation retry reuses the sandbox, the runner calls `ClearIterationArtifacts` before the next iteration. Every runtime runs the shared `clearStrayProcesses` sweep first (it terminates the processes the previous iteration left running as the sandbox user, sparing the exec channel and the `sandbox.KeepAliveCommand` main process), then deletes the iteration's output, sessions and debug log. A failed sweep is reported as a warning and never fails the iteration. The runner holds its sandbox lock (`withSandboxLock` in `internal/cli/run.go`) across the call so the credential refreshers' uploads are never killed mid-write. The same sweep runs as `TerminateStrayProcesses` right after an iteration ends at its budget: OpenShell's exec timeout drops the relay but leaves the agent's processes running, and a killed iteration is not followed by another `ClearIterationArtifacts` (see [`fullsend run` § Budget and deadline](../cli/run.md#budget-and-deadline)).

Expand Down Expand Up @@ -404,6 +413,12 @@ Two traps when reproducing by hand:
| `FULLSEND_CANARY_TOKEN` | both canary hooks | no-ops when empty; supply it via harness `env.sandbox`/`host_files` |
| `FULLSEND_TRACE_ID` | all scripts | correlates findings with the run |

The runner-written rows in this table are entries in the generated
[sandbox environment contract](../normative/sandbox-env/v1/README.md) — the
machine-checkable schemas listing every variable the runner injects into
the sandbox, per gate and per runtime, and the keys it reserves from
harness override. The schemas are the source of truth; this table is prose.

### Suppression reachability

Under Claude Code a non-zero-exit command never reaches `PostToolUse` at all, so the suppressors only ever see zero-exit output; a tool that exits 0 with nothing to say is the case that used to be summarized as "passed". Adapters whose post-tool event also fires for failures (pi's `tool_result`) do deliver failed calls to the same chain, which is why the positive-evidence rule matters on both.
Expand Down
6 changes: 6 additions & 0 deletions docs/guides/dev/cli-internals.md
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,12 @@ Vendoring commit messages use title + body (upload and stale delete). `admin ins
└─────────────────────────────────────────────────────────────────┘
```

The `bootstrapEnv()` writes and the `iteration.env` names in this diagram are
the runner's exports. The full, machine-checkable inventory — what every
sandbox receives, per gate and per runtime, and what arrives only through
harness configuration — is the generated [sandbox environment
contract](../../normative/sandbox-env/v1/README.md).

### Sandbox Constants

```go
Expand Down
2 changes: 1 addition & 1 deletion docs/guides/user/bring-your-own-agent.md
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ Key patterns to note:
- **`host_files`** copy credentials from the trusted runner into the sandbox. `expand: true` resolves `${VAR}` references before copying.
- **`validation_loop.schema`** references the JSON schema file directly — the validation script checks agent output against it.
- **`overlays`** uses CEL `when` expressions to conditionally apply scripts, skills, providers, openshell, host_files, and env vars. Resolution merges all matching entries in order: every entry whose `when` evaluates to true is applied, with later matches taking precedence over earlier ones. The CEL environment exposes `event` (the triggering event), `runtime.forge` (the effective forge platform), and `config` (per-repo config from config.yaml). When running without an event context (e.g., `fullsend run` or `fullsend lock`), `event` is an empty map — use `has(event.source)` to guard event field access: `has(event.source) && event.source.system == "jira"` instead of just `event.source.system == "jira"` to avoid "no such key" errors.
- **`common/env/gcp-vertex.env`** is referenced by relative path because both files live in the same repo. If your agent lives in a different repo, reference it by URL (see [Harness Field Reference — Referencing resources](../../reference/harness-reference.md#referencing-resources-local-vs-remote)) or copy it locally.
- **`common/env/gcp-vertex.env`** is referenced by relative path because both files live in the same repo. If your agent lives in a different repo, reference it by URL (see [Harness Field Reference — Referencing resources](../../reference/harness-reference.md#referencing-resources-local-vs-remote)) or copy it locally. The variables it delivers reach the sandbox through harness configuration rather than runner guarantee — they are catalogued as `harness_delivered` in the [sandbox environment contract](../../normative/sandbox-env/v1/README.md).

For the complete list of harness fields, see the [Harness Field Reference](../../reference/harness-reference.md).

Expand Down
4 changes: 3 additions & 1 deletion docs/guides/user/customizing-agents.md
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,9 @@ shell-behavior variables like `HTTPS_PROXY`, `SSL_CERT_FILE`,
`GIT_SSH_COMMAND` and `NODE_OPTIONS`, instead of exporting them into the
sandbox. Matching is case-insensitive, and `fullsend run` warns about every
key it drops. The gate covers `env.sandbox` only; it is not a reason to move
those settings into `.env.d` files.
those settings into `.env.d` files. The full reserved set is published in the
generated [sandbox environment
contract](../../normative/sandbox-env/v1/README.md).

For the full list, how to check a harness with `fullsend lint` or
`fullsend lock`, and where proxy and certificate settings go instead, see
Expand Down
4 changes: 3 additions & 1 deletion docs/guides/user/running-agents-locally.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,9 @@ with the credential kept out of the sandbox by an OpenShell provider. In CI the
identity ([OpenAI Workload Identity](../infrastructure/openai-workload-identity.md)); on your
machine there is no such identity, so use an API key from the same OpenAI project. Put it in an
environment file, like the GCP settings above — never in the harness YAML and never under
`env.sandbox` (the runner refuses to export it into the sandbox):
`env.sandbox` (the runner refuses to export it into the sandbox; `OPENAI_API_KEY` is in the
reserved set published by the [sandbox environment
contract](../../normative/sandbox-env/v1/README.md)):

```bash
# fullsend-openai.env
Expand Down
Loading
Loading