Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
12 changes: 10 additions & 2 deletions docs/contributing/runtime-implementation.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ The sandbox has two key directories that map to Claude Code's config levels (plu
/sandbox/
├── pi-config/ ← PI_CODING_AGENT_DIR (pi runtime; written by PiRuntime.Bootstrap)
│ ├── APPEND_SYSTEM.md Agent definition body (appended to pi's default system prompt)
│ ├── settings.json defaultProjectTrust: never, quietStartup, retry/compaction on
│ ├── settings.json defaultProjectTrust: never, defaultTools (all built-ins), quietStartup, retry/compaction on
│ ├── skills/<name>/SKILL.md Harness skills (pi's native skill discovery)
│ ├── hooks/*.py Security hook scripts (same files as claude-config/hooks/)
│ ├── fullsend-hooks.js Hook adapter extension (loaded with -e; --no-extensions otherwise)
Expand Down Expand Up @@ -463,7 +463,15 @@ Parity with `claude -p --dangerously-skip-permissions`, verified against pi v0.8

### Process and exit codes

- **Hardening levers in use** — `Run` executes `pi --print --mode json --no-approve --no-extensions --no-prompt-templates --no-themes --session-dir /sandbox/pi-config/sessions [-e /usr/local/share/pi-extensions/anthropic-vertex | -e /usr/local/share/pi-extensions/xai-vertex] [-e /sandbox/pi-config/fullsend-hooks.js] [--tools ...] --model <provider/id> --thinking <effort|high> '<RunParams.Prompt, default "Run the agent task">' </dev/null [2>>/sandbox/workspace/pi-debug.log]`; `settings.json` sets `defaultProjectTrust: never` (repo-owned `.pi/` never loaded); `PI_OFFLINE=1`/`PI_TELEMETRY=0`/`PI_SKIP_VERSION_CHECK=1` come from `EnvExports`. Context files (`AGENTS.md`) and skills stay on — they are the harness's own inputs. `PI_CODING_AGENT_DIR/extensions/` is arbitrary TypeScript loaded at startup and the config dir is not a permission boundary, which is why only the explicit `-e` paths load (at most one vendored provider extension plus the hook adapter). Right after `.env` is sourced, `Run` re-exports `EnvExports()` (`PI_CODING_AGENT_DIR`, the session dir, the offline switches) so a rewritten `.env` cannot relocate pi's config directory. For the built-in `openai` provider (`openai/<id>`, [ADR 0092](../ADRs/0092-openai-wif-credential-delivery.md)) no extension loads and no `--api-key` is passed; `Run` instead seeds `auth.json` under `PI_CODING_AGENT_DIR` with the placeholder the sandbox environment carries for `OPENAI_API_KEY` (`PiOpenAIAuthSeed`, before `.env` is sourced), because pi re-reads that file on every revision change and resolves the key per request — the runner re-runs the same seed through `sandbox exec` after each credential refresh, which is what lets a running iteration follow a refresh on OpenShell 0.0.115, where a revision-scoped placeholder stays pinned to its generation and the unrevisioned alias is refused (`--api-key` would outrank the file and pin the iteration). It unsets `OPENAI_BASE_URL`/`AZURE_OPENAI_API_KEY`/`OPENAI_API_KEY`/`NODE_OPTIONS`/`NODE_PATH` after `.env`, fails the iteration with exit 1 when the environment holds anything but a gateway placeholder at seed time (before `.env`), and runs a config-dir integrity guard that exits 98 when `models.json` exists or `auth.json` is anything but pi's own `{}` or exactly the seeded placeholder entry — `models.json` is the only way to move the provider's base URL, a redirect to another allowed REST host is the placeholder-leak path ADR 0025 describes, and pi itself writes an empty `auth.json` on every start so only its content counts. The guard runs before the agent-writable `.env` is sourced and again after it behind `unset -f test command grep tr sed printf`, whether or not hooks are enabled.
- **Hardening levers in use**
- `Run` executes `pi --print --mode json --no-approve --no-extensions --no-prompt-templates --no-themes --session-dir /sandbox/pi-config/sessions [-e /usr/local/share/pi-extensions/anthropic-vertex | -e /usr/local/share/pi-extensions/xai-vertex] [-e /sandbox/pi-config/fullsend-hooks.js] [--tools ...] --model <provider/id> --thinking <effort|high> '<RunParams.Prompt, default "Run the agent task">' </dev/null [2>>/sandbox/workspace/pi-debug.log]`.
- `settings.json` sets `defaultProjectTrust: never` (repo-owned `.pi/` never loaded) and `defaultTools: [read, bash, edit, write, grep, find, ls]` — pi alone activates only the first four; `--tools`, when emitted, replaces the set. The `grep` and `find` tools shell out to `rg` and `fd` (pi's `utils/tools-manager.ts`), which the sandbox image ships because `PI_OFFLINE=1` and the egress policy both stop pi's own GitHub-release download.
- `PI_OFFLINE=1`/`PI_TELEMETRY=0`/`PI_SKIP_VERSION_CHECK=1` come from `EnvExports`. Context files (`AGENTS.md`) and skills stay on — they are the harness's own inputs.
- `PI_CODING_AGENT_DIR/extensions/` is arbitrary TypeScript loaded at startup and the config dir is not a permission boundary, which is why only the explicit `-e` paths load (at most one vendored provider extension plus the hook adapter).
- Right after `.env` is sourced, `Run` re-exports `EnvExports()` (`PI_CODING_AGENT_DIR`, the session dir, the offline switches) so a rewritten `.env` cannot relocate pi's config directory.
- For the built-in `openai` provider (`openai/<id>`, [ADR 0092](../ADRs/0092-openai-wif-credential-delivery.md)) no extension loads and no `--api-key` is passed; `Run` instead seeds `auth.json` under `PI_CODING_AGENT_DIR` with the placeholder the sandbox environment carries for `OPENAI_API_KEY` (`PiOpenAIAuthSeed`, before `.env` is sourced), because pi re-reads that file on every revision change and resolves the key per request. The runner re-runs the same seed through `sandbox exec` after each credential refresh, which is what lets a running iteration follow a refresh on OpenShell 0.0.115, where a revision-scoped placeholder stays pinned to its generation and the unrevisioned alias is refused (`--api-key` would outrank the file and pin the iteration).
- `Run` unsets `OPENAI_BASE_URL`/`AZURE_OPENAI_API_KEY`/`OPENAI_API_KEY`/`NODE_OPTIONS`/`NODE_PATH` after `.env`, and fails the iteration with exit 1 when the environment holds anything but a gateway placeholder at seed time (before `.env`).
- A config-dir integrity guard exits 98 when `models.json` exists or `auth.json` is anything but pi's own `{}` or exactly the seeded placeholder entry — `models.json` is the only way to move the provider's base URL, a redirect to another allowed REST host is the placeholder-leak path ADR 0025 describes, and pi itself writes an empty `auth.json` on every start so only its content counts. The guard runs before the agent-writable `.env` is sourced and again after it behind `unset -f test command grep tr sed printf`, whether or not hooks are enabled.
- **`--mode json` exits 0 on model error** — only text mode maps `stopReason: error|aborted` to exit 1. `parsePiStream` is the intended detector (assistant `stopReason` on `message_end.message` / last `agent_end.messages` entry) for the runner's exit-0-override (#2786/#5361). `Run` tees the stream to `output.jsonl`, `ParseTranscriptFile` reads it, and `Run` itself returns 1 on a stream-reported error, so the override and the runtime agree.
- **Exit code** — `Run` returns 1 when pi exited 0 but the stream's single `ResultEvent` reports an error (model error, incomplete stream), so the runner's exit-0 override and this agree; `ParseTranscriptFile` gives the same verdict from the tee'd `output.jsonl`.

Expand Down
2 changes: 1 addition & 1 deletion docs/contributing/sandbox-topology.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ ghcr.io/nvidia/openshell-community/sandboxes/base (upstream)

| Image | Agents | Run frequency | Key additions over parent |
|-------|--------|---------------|--------------------------|
| `fullsend-sandbox` | triage, prioritize, retro | High (most agent runs) | Claude Code, pi (pinned; opt-in runtime, #6464), jq, gitleaks, acli, pre-commit, gitlint, tirith |
| `fullsend-sandbox` | triage, prioritize, retro | High (most agent runs) | Claude Code, pi (pinned; opt-in runtime, #6464), ripgrep + fd (pi grep/find backends), jq, gitleaks, acli, pre-commit, gitlint, tirith |
| `fullsend-code` | code, fix, review | Lower (code/fix are the least-run agents; review runs per-PR) | Go toolchain, scan-secrets, gopls, lychee |

Harness definitions that map agents to images live in
Expand Down
4 changes: 3 additions & 1 deletion images/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ ghcr.io/nvidia/openshell-community/sandboxes/base (upstream, multi-arch)

| Image | Directory | Description |
|-------|-----------|-------------|
| `fullsend-sandbox` | [`images/sandbox/`](sandbox/) | Base sandbox with Claude Code, jq, acli, gitleaks, tirith, pre-commit, and gitlint. |
| `fullsend-sandbox` | [`images/sandbox/`](sandbox/) | Base sandbox with Claude Code, pi, ripgrep + fd (pi grep/find backends), jq, acli, gitleaks, tirith, pre-commit, and gitlint. |
| `fullsend-code` | [`images/code/`](code/) | Extends `fullsend-sandbox` with Go toolchain and scan-secrets wrapper. Used by the code-implementation agent. |

Both images are built for **linux/amd64** and **linux/arm64**.
Expand Down Expand Up @@ -138,6 +138,8 @@ Every binary downloaded during the build is **version-pinned** and
| ProtectAI DeBERTa model (runner) | `PROTECTAI_MODEL_REV` + per-file SHA256 | `sha256sum -c` |
| libtokenizers (runner) | `TOKENIZERS_VERSION` + `TOKENIZERS_SHA256_{AMD64,ARM64}` | `sha256sum -c` |
| Gitleaks | `GITLEAKS_VERSION` + `GITLEAKS_SHA256_{AMD64,ARM64}` | `sha256sum -c` |
| ripgrep | `RIPGREP_VERSION` + `RIPGREP_SHA256_{AMD64,ARM64}` | `sha256sum -c` + version assertion |
| fd | `FD_VERSION` + `FD_SHA256_{AMD64,ARM64}` | `sha256sum -c` + version assertion |
| Tirith | `TIRITH_VERSION` + `TIRITH_SHA256_{AMD64,ARM64}` | `sha256sum -c` |
| Go toolchain | `GO_VERSION` + `GO_SHA256_{AMD64,ARM64}` | `sha256sum -c` |
| Claude Code | `CLAUDE_CODE_VERSION` ARG + npm version pin | npm registry integrity check |
Expand Down
47 changes: 47 additions & 0 deletions images/sandbox/Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
# #6464) + the pi-anthropic-vertex extension
# (tag + SHA256 pinned under /usr/local/share/pi-extensions)
# - jq (JSON parsing in agent scripts and skills)
# - ripgrep + fd (backends of pi's built-in grep/find tools; SHA256-verified
# static builds, versions asserted at build time)
# - gitleaks (secret scanner, SHA256-verified)
# - acli (Atlassian CLI for Jira issue queries)
# - pre-commit + gitlint (repo hook runner + commit message validator)
Expand Down Expand Up @@ -81,6 +83,10 @@ RUN NPM_CLAUDE="$(npm prefix -g)/bin/claude" \
# in-sandbox fixture capture run against a pinned, reviewed version
# (internal/runtime/testdata/pi/regen.sh reads the pin from this file).
#
# 0.84.4 is the floor for Gemini on Vertex: 0.84.3 bundles https-proxy-agent
# without its named export, so every google-vertex request fails with
# "HttpsProxyAgent is not a constructor" whenever HTTPS_PROXY is set — which
# the OpenShell sandbox always does (earendil-works/pi#8610, fixed in 0.84.4).
# To update: bump PI_VERSION; renovate tracks this ARG via a customManagers
# regex entry in renovate.json. pi releases ~weekly minors and has changed
# its --mode json wire shape within a minor before (0.84.0) — the pi stream
Expand Down Expand Up @@ -228,6 +234,47 @@ RUN case "$TARGETARCH" in \
&& chmod +x /usr/local/bin/gitleaks \
&& rm /tmp/gitleaks.tar.gz

# ---------------------------------------------------------------------------
# ripgrep + fd — the search backends of pi's built-in `grep` and `find`
# tools (packages/coding-agent/src/utils/tools-manager.ts resolves `rg` and
# `fd` from PATH). Without them both tools fail with "<tool> is not available
# and could not be downloaded": the runtime exports PI_OFFLINE=1, which makes
# pi skip its GitHub-release download, and the egress policy would block that
# download anyway. Static musl builds; pinned version + per-arch SHA256 like
# gitleaks. Claude Code bundles its own ripgrep, so only pi needs these,
# but they sit on PATH for every runtime. Release tarballs rather than
# apt: Debian installs fd as `fdfind`, which pi accepts, but the musl builds
# are static and version-asserted below.
# To update: bump the versions and refresh the SHA256s from
# https://github.com/BurntSushi/ripgrep/releases/download/<ver>/ripgrep-<ver>-<arch>-unknown-linux-musl.tar.gz.sha256
# sha256sum <(curl -fsSL https://github.com/sharkdp/fd/releases/download/v<ver>/fd-v<ver>-<arch>-unknown-linux-musl.tar.gz)
ARG RIPGREP_VERSION=15.2.0
ARG RIPGREP_SHA256_AMD64=33e15bcf1624b25cdd2a55813a47a2f95dbe126268203e76aa6a585d1e7b149c
ARG RIPGREP_SHA256_ARM64=800b1e7206afe799dfb5a6901f23147cfaabe0e52210538100f61e86e1740915
ARG FD_VERSION=10.5.0
ARG FD_SHA256_AMD64=761c72dc8e120d85b22292063be8a796e2eeb20eb3e4f38b8fa2343ccf3514a7
ARG FD_SHA256_ARM64=d76c4317f7d5dba69f8a2a15856c90c777e7f0dd4e85f0de8c76de6992c374d4
RUN case "$TARGETARCH" in \
amd64) RS_ARCH="x86_64"; RG_SHA="$RIPGREP_SHA256_AMD64"; FD_SHA="$FD_SHA256_AMD64" ;; \
arm64) RS_ARCH="aarch64"; RG_SHA="$RIPGREP_SHA256_ARM64"; FD_SHA="$FD_SHA256_ARM64" ;; \
*) echo "unsupported TARGETARCH=$TARGETARCH" >&2; exit 1 ;; \
esac \
&& curl -fsSL --retry 3 --retry-delay 5 \
"https://github.com/BurntSushi/ripgrep/releases/download/${RIPGREP_VERSION}/ripgrep-${RIPGREP_VERSION}-${RS_ARCH}-unknown-linux-musl.tar.gz" \
-o /tmp/ripgrep.tar.gz \
&& echo "${RG_SHA} /tmp/ripgrep.tar.gz" | sha256sum -c - \
&& tar xzf /tmp/ripgrep.tar.gz -C /usr/local/bin --strip-components=1 "ripgrep-${RIPGREP_VERSION}-${RS_ARCH}-unknown-linux-musl/rg" \
&& rm /tmp/ripgrep.tar.gz \
&& curl -fsSL --retry 3 --retry-delay 5 \
"https://github.com/sharkdp/fd/releases/download/v${FD_VERSION}/fd-v${FD_VERSION}-${RS_ARCH}-unknown-linux-musl.tar.gz" \
-o /tmp/fd.tar.gz \
&& echo "${FD_SHA} /tmp/fd.tar.gz" | sha256sum -c - \
&& tar xzf /tmp/fd.tar.gz -C /usr/local/bin --strip-components=1 "fd-v${FD_VERSION}-${RS_ARCH}-unknown-linux-musl/fd" \
&& rm /tmp/fd.tar.gz \
&& chmod 755 /usr/local/bin/rg /usr/local/bin/fd \
&& rg --version | grep -q "^ripgrep ${RIPGREP_VERSION} " \
&& fd --version | grep -q "^fd ${FD_VERSION}$"

# ---------------------------------------------------------------------------
# pre-commit + gitlint — pre-commit runs repo-defined hooks (formatting,
# linting, etc.) on changed files. gitlint validates commit message format.
Expand Down
4 changes: 3 additions & 1 deletion internal/runtime/pi_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,9 @@ func parseClaudeToolSpecs(specs []string) (tools, bashAllowlist []string) {

// piToolForClaude maps the Claude Code tool names an agent definition may
// list to pi's built-in tools (packages/coding-agent/src/core/tools/index.ts:
// read, bash, edit, write, grep, find, ls). Claude tools without a pi
// read, bash, edit, write, grep, find, ls — every non-Windows built-in; pi
// also has powershell — all activated via settings.json defaultTools, since
// pi alone starts with only the first four). Claude tools without a pi
// counterpart are reported as unsupported; Skill maps to no tool (pi's
// skills are prompt-driven), and Bootstrap adds read for it, since pi only
// emits the skills section of the system prompt when read is active.
Expand Down
15 changes: 13 additions & 2 deletions internal/runtime/pi_bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ type piManifest struct {
Description string `json:"description,omitempty"`
// Model is the agent definition's model; the harness model wins at Run.
Model string `json:"model,omitempty"`
// Tools are pi tool names for --tools; nil means pi's default set.
// Tools are pi tool names for --tools; nil means the settings.json
// defaultTools set (piDefaultTools).
Tools []string `json:"tools"`
// BashAllowlist is the Bash(a,b) first-token allowlist from the agent
// definition. Under Claude Code it is steering, not a security control
Expand Down Expand Up @@ -232,17 +233,27 @@ const piNoSubagentNote = "\n## Runtime note\n\n" +
"sub-agent definition yourself, in the listed order, with the same context package, " +
"and treat each output as that sub-agent's result.\n"

// piDefaultTools is the built-in tool set activated when the agent lists
// no tools: pi 0.84.x itself starts with only read, bash, edit and write
// (packages/coding-agent/src/core/sdk.ts defaultActiveToolNames — grep,
// find and ls are registered but inactive), which left the search tools
// unavailable to every agent without `tools:` frontmatter. The sandbox
// image ships rg and fd for grep/find (images/sandbox/Containerfile).
var piDefaultTools = []string{"read", "bash", "edit", "write", "grep", "find", "ls"}
Comment thread
qodo-code-review[bot] marked this conversation as resolved.
Resolved

// piSettingsJSON is the locked-down global settings for the sandbox run.
// defaultProjectTrust "never" means a repo-owned .pi/ (settings, extensions,
// SYSTEM.md) is never loaded in non-interactive modes; skills as slash
// commands are irrelevant headless; retry/compaction stay on so a transient
// provider error or a long session does not end the run
// (parsePiStream models both).
// (parsePiStream models both); defaultTools activates every non-Windows
// built-in (see piDefaultTools; pi also ships powershell) — --tools, when Run emits it, still replaces this.
func piSettingsJSON() ([]byte, error) {
settings := map[string]any{
"defaultProjectTrust": "never",
"quietStartup": true,
"enableSkillCommands": false,
"defaultTools": piDefaultTools,
"retry": map[string]any{"enabled": true},
"compaction": map[string]any{"enabled": true},
}
Expand Down
18 changes: 18 additions & 0 deletions internal/runtime/pi_bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ func TestPiRuntimeBootstrap_WritesConfigAndManifest(t *testing.T) {
require.NoError(t, json.Unmarshal(storedUpload(t, store, cfg+"/settings.json"), &settings))
assert.Equal(t, "never", settings["defaultProjectTrust"])
assert.Equal(t, false, settings["enableSkillCommands"])
assert.Equal(t, []any{"read", "bash", "edit", "write", "grep", "find", "ls"}, settings["defaultTools"])

ext := string(storedUpload(t, store, cfg+"/fullsend-hooks.js"))
assert.Contains(t, ext, "export default function")
Expand Down Expand Up @@ -157,6 +158,10 @@ func TestPiRuntimeBootstrap_NoSecurityNoHooks(t *testing.T) {
require.NoError(t, json.Unmarshal(storedUpload(t, store, PiRuntime{}.ConfigDir()+"/fullsend-manifest.json"), &m))
assert.Nil(t, m.Hooks)
assert.Nil(t, m.Tools)
var settings map[string]any
require.NoError(t, json.Unmarshal(storedUpload(t, store, PiRuntime{}.ConfigDir()+"/settings.json"), &settings))
assert.Equal(t, []any{"read", "bash", "edit", "write", "grep", "find", "ls"}, settings["defaultTools"],
"an agent without tools: frontmatter gets every built-in through defaultTools, not pi's four-tool default")
assert.Equal(t, "enforce", m.BashAllowlistMode, "FULLSEND_PI_BASH_ALLOWLIST=enforce opts into blocking")
_, err := os.Stat(filepath.Join(store, strings.ReplaceAll(PiRuntime{}.ConfigDir()+"/fullsend-hooks.js", "/", "_")))
assert.True(t, os.IsNotExist(err), "no hook extension without security config")
Expand Down Expand Up @@ -420,3 +425,16 @@ func TestPiRuntimeClearIterationArtifacts(t *testing.T) {
require.NoError(t, err)
Comment thread
waynesun09 marked this conversation as resolved.
Resolved
assert.Contains(t, string(log), "rm -rf '/sandbox/workspace'/output/* '/sandbox/pi-config/sessions'/* '/sandbox/workspace/pi-debug.log'")
}

// TestPiDefaultTools_CoversToolMap keeps the settings.json default set and
// the Claude→pi tool map from drifting apart: every pi tool an agent can
// name must be active when it lists no tools.
func TestPiDefaultTools_CoversToolMap(t *testing.T) {
defaults := map[string]bool{}
for _, name := range piDefaultTools {
defaults[name] = true
}
Comment thread
waynesun09 marked this conversation as resolved.
Resolved
for claudeName, piName := range piToolForClaude {
assert.Truef(t, defaults[piName], "pi tool %q (mapped from %s) is missing from piDefaultTools", piName, claudeName)
}
}
2 changes: 1 addition & 1 deletion internal/runtime/pi_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ func buildPiRunCommand(params RunParams, m *piManifest) string {
tools := m.Tools
if len(tools) == 0 {
// An agent that lists only tools pi cannot provide (or only
// Skill) gets no built-in tools rather than pi's defaults.
// Skill) gets no built-in tools rather than the defaultTools set.
parts = append(parts, "--no-builtin-tools")
} else {
parts = append(parts, "--tools "+shellQuote(strings.Join(tools, ",")))
Expand Down
Loading
Loading