mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-12 22:56:58 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - Runner E2E evals run real agents against a real Paperclip server, then grade the result > - A local cell runs the product from the same checkout as the eval, as the same OS user > - In run 42472276601 an OpenCode agent read the eval's own scenario YAML and grader from that checkout > - An agent that can read the oracle can steer toward it instead of the user's request, so the eval stops measuring the product > - This pull request hides the eval harness from every local native agent process and removes eval names from fixtures > - The benefit is that a passing chat eval again shows product behavior, not oracle access ## Linked Issues or Issue Description Refs #19614 (the chat catalog eval harness that these graders belong to). **What happened** In run 42472276601, cell `chat-features.runner-opencode.local.access.cli-authorization` (OpenCode, DeepSeek), the agent printed its environment and saw the checkout path in `PATH` and `PAPERCLIP_RUNTIME_NOTIFICATION_HELPER`. OpenCode's `read` and `grep` tools were denied by its `external_directory` policy. The agent then used its `bash` tool with absolute paths, which that policy does not gate. It listed `/home/runner/_work/paperclip/paperclip`, read `docs/cli/*.md` and `cli/src/commands/client/*.ts`, ran `grep -rn` over `tests/runner-e2e`, and found the query in `chat-full-catalog-testops-manifest.json`. It then read `tests/runner-e2e/chat-scenarios/access.yaml`, the manifest entry, and the case grader `chat-catalog-domains/identity-cli-authorization.ts`. Its reasoning said: "This is the exact test case!" Separately, fixture company names contained the case id, for example `Runner E2E chat-features.runner-opencode.local.access.private-resource …`, and an agent noticed that it was in a test. **Expected behavior** The agent under test cannot read the eval's scenarios, fixtures, graders or captured evidence. It keeps everything that it needs: its workspace, its home, the product skills, the product packages and temporary files. The names it can see do not contain case ids, "E2E" or "test". **Steps to reproduce** 1. Dispatch `runner-full-stack-e2e.yml` for any `chat-features.runner-opencode.local.*` cell on master. 2. In the agent run, use bash to execute `grep -rn expected_outcome /home/runner/_work/paperclip/paperclip/tests/runner-e2e/chat-scenarios`. 3. The command returns the scenario expectations. With this change, the command returns `Permission denied` and exit code 2. ## What Changed - `tests/runner-e2e/agent-filesystem-sandbox.py` (new): applies a Linux Landlock domain that grants filesystem access everywhere except the hidden paths, sets `no_new_privs`, checks in-process that the hidden paths are denied, then `execv`s the command with the same PID, argv and environment. - `tests/runner-e2e/agent-filesystem-sandbox.ts` (new): selects the hidden paths (`tests/`, `.manual-private-trusted/`, the private evidence directory, `RUNNER_TEMP`). It never hides the agent's temporary root, the checkout root or the shared temporary directory. It runs a setup probe, logs the result and fails closed in CI. Then it wraps each `paperclip-runnerd` spawn of the E2E server. - Follow-up: run 42445668869 showed that the hidden list missed two places. A fixture worker listed Playwright's compiled copy of the harness and graders with source maps (`/tmp/playwright-transform-cache-1001/`). An agent in another run listed the attempt root's `artifacts-private/`, `control/` and `selected-private-inputs/` under `/tmp`. A sandboxed attempt now creates its root in `/var/tmp`. The reason: Landlock hides a path by leaving its ancestors ungranted, and agents must still create files in `/tmp`. The launcher sets `PWTEST_CACHE_DIR` to a hidden child of that root and removes the default cache. The hidden list covers the four private children of the root, including children that are created after runnerd starts. The probe also checks that the default Playwright cache is not listable. - `tests/runner-e2e/launch.ts`: passes the selection to the server process. The selection applies only to Linux local native cells. It does not apply to Codex cells (Codex's bubblewrap sandbox cannot mount under Landlock), installed-release launches, legacy adapters or Daytona. - `tests/runner-e2e/server-entry.ts`: installs the sandbox before the product starts. The product server itself stays unrestricted because it loads this entry from the harness. - `tests/runner-e2e/fixture-names.ts` (new), `catalog.ts`, `live-fixtures.ts`: fixture company, agent, environment, secret, AI connection and project names and descriptions use a neutral word and an 8-character digest suffix. They do not contain case ids or "Runner E2E". No grader or harness lookup reads these names. - `tests/runner-e2e/agent-filesystem-sandbox.test.ts` (new): tests the selection, the launch rewrite and the server-entry order. On Linux with Landlock, it also tests that a sandboxed `grep` over a fake `tests/` dir is denied while the product file stays readable. - `tests/runner-e2e/SECURITY.md`: documents the boundary and its limits. - The trusted files `manual-private-handoff.ts`, `manual-private-retention.ts` and `manual-private-report-assets.ts` are byte-identical to master. ## Verification - `pnpm exec vitest run --config tests/runner-e2e/vitest.config.ts tests/runner-e2e/agent-filesystem-sandbox.test.ts tests/runner-e2e/live-fixtures.test.ts tests/runner-e2e/catalog.test.ts tests/runner-e2e/codex-ci-sandbox.test.ts tests/runner-e2e/server-entry.test.ts`: 151 passed, 1 skipped. The Landlock test is skipped on macOS. `npx tsc --noEmit -p tests/runner-e2e` shows no errors in the changed files. - Paid run [42480314919](https://github.com/paperclipai/paperclip/actions/runs/42480314919) for `chat-features.runner-opencode.local.agents.change-manager` ran on branch `chat-eval/eval-isolation-verify`, which is this commit cherry-picked onto the chat catalog candidate. The cell passed. Its `server.log` records: - `probe … "harnessFile":"denied","harnessDirectory":"denied","productFile":"readable","temporaryWrite":"allowed"`, and `denied` for each of `…/paperclip/tests`, `…/.manual-private-trusted`, `…/_temp/manual-private-evidence-*/capture`, `…/_temp/manual-private-evidence-*` and `…/_temp`. `"failures":[]`. - `runnerd launched inside the sandbox (pid 3548)`. - The fixture company was `Company cc369a2e`. No captured snapshot contains "Runner E2E". - The probe is a regression check on every local native cell: a missing or ineffective sandbox stops the attempt in CI before an agent starts. ## Risks - Landlock does not hide that a path exists. `stat` of `tests/runner-e2e` still succeeds (the probe logs `harnessDirectoryStat: visible`). Reading and listing are denied. - Directories above a hidden path (for example `/`, `/home/runner` and the checkout root) cannot be listed. New top-level entries in those directories are not accessible after launch. Agent state, `HOME` and temporary files are in `/tmp`, which stays fully granted. - Not covered: Codex cells, legacy adapters, installed-release launches and macOS. An agent that can reach the Docker daemon can still mount the checkout into a container. `ps` still shows the launcher's command line, which includes the case id. The temporary root (`paperclip-runner-e2e-*`) and instance id (`runner-e2e-*`) in the agent's paths still say "e2e". The chat catalog candidate depends on those prefixes, so this PR does not rename them. - Python 3 must be present on Linux runners. Ubuntu runners have it, and the harness already uses it. ## Model Used - Anthropic Claude Opus 5.5 (`claude-opus-5-5`), agentic coding with tool use (shell, file edits, GitHub CLI). ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [ ] All Paperclip CI gates are green - [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
235 lines
13 KiB
TypeScript
235 lines
13 KiB
TypeScript
import { execFileSync } from "node:child_process";
|
|
import { mkdtempSync, realpathSync, rmSync } from "node:fs";
|
|
import { mkdir, mkdtemp, readFile, realpath, rm, writeFile } from "node:fs/promises";
|
|
import os from "node:os";
|
|
import path from "node:path";
|
|
import { afterEach, describe, expect, it } from "vitest";
|
|
import {
|
|
HARNESS_PRIVATE_TEMPORARY_CHILDREN,
|
|
agentFilesystemSandboxConfig,
|
|
agentTemporaryParent,
|
|
defaultPlaywrightCacheDirectory,
|
|
playwrightCacheDirectory,
|
|
isRunnerdLaunch,
|
|
parseAgentFilesystemSandboxConfig,
|
|
probeAgentFilesystemSandbox,
|
|
pythonExecutable,
|
|
sandboxedInvocation,
|
|
agentFilesystemSandboxHelper,
|
|
wrapRunnerdSpawn,
|
|
wrapRunnerdLaunch,
|
|
gitStorePaths,
|
|
RUNNERD_LAUNCH_APIS,
|
|
} from "./agent-filesystem-sandbox.js";
|
|
import { runnerMatrix } from "./catalog.js";
|
|
|
|
const repositoryRoot = "/work/paperclip";
|
|
const temporaryRoot = "/var/tmp/paperclip-runner-e2e-abc";
|
|
const cell = (id: string) => {
|
|
const execution = runnerMatrix.find((candidate) => candidate.id === id);
|
|
if (!execution) throw new Error(`missing ${id}`);
|
|
return execution;
|
|
};
|
|
const gitStores = ["/work/paperclip/.git"];
|
|
const opencodeLocal = cell("task-workspaces.runner-opencode.local.task-directory-repository-resume");
|
|
const base = {
|
|
platform: "linux" as const,
|
|
env: { GITHUB_ACTIONS: "true", RUNNER_TEMP: "/work/_temp" },
|
|
executions: [opencodeLocal],
|
|
repositoryRoot,
|
|
temporaryRoot,
|
|
privateDir: "/work/_temp/manual-private-evidence-x/capture",
|
|
evidenceRoot: "/work/_temp/manual-private-evidence-x",
|
|
installedRelease: false,
|
|
sharedTemporary: "/tmp",
|
|
gitStores,
|
|
};
|
|
|
|
describe("agent filesystem sandbox selection", () => {
|
|
it("hides the harness, the trusted copy and captured evidence from local native agents", () => {
|
|
expect(agentFilesystemSandboxConfig(base)).toEqual({
|
|
hidden: [
|
|
"/work/paperclip/tests",
|
|
"/work/paperclip/.git",
|
|
"/work/paperclip/.manual-private-trusted",
|
|
`${temporaryRoot}/artifacts-private`,
|
|
`${temporaryRoot}/control`,
|
|
`${temporaryRoot}/selected-private-inputs`,
|
|
`${temporaryRoot}/playwright-transform-cache`,
|
|
"/work/_temp/manual-private-evidence-x/capture",
|
|
"/work/_temp/manual-private-evidence-x",
|
|
"/work/_temp",
|
|
],
|
|
required: true,
|
|
});
|
|
});
|
|
|
|
it("hides the attempt's private children and Playwright cache when its root is outside the shared temporary directory", () => {
|
|
const config = agentFilesystemSandboxConfig(base);
|
|
expect(config?.hidden).toContain(playwrightCacheDirectory(temporaryRoot));
|
|
expect(config?.hidden).not.toContain(temporaryRoot);
|
|
expect(HARNESS_PRIVATE_TEMPORARY_CHILDREN).toContain("playwright-transform-cache");
|
|
expect(defaultPlaywrightCacheDirectory("/tmp")).toMatch(/^\/tmp\/playwright-transform-cache-/);
|
|
});
|
|
|
|
it("fails closed in CI when harness material sits where it cannot be hidden", () => {
|
|
const underShared = { ...base, temporaryRoot: "/tmp/paperclip-runner-e2e-abc", privateDir: "/tmp/paperclip-runner-e2e-abc/artifacts-private" };
|
|
expect(() => agentFilesystemSandboxConfig(underShared)).toThrow(/agent_filesystem_sandbox_incomplete: .*artifacts-private/);
|
|
expect(() => agentFilesystemSandboxConfig({ ...base, repositoryRoot: "/tmp/checkout" })).toThrow(/\/tmp\/checkout\/tests/);
|
|
});
|
|
|
|
it("keeps a sandboxed attempt's root out of the shared temporary directory", () => {
|
|
const parent = agentTemporaryParent(true);
|
|
if (process.platform === "linux") expect(parent).toBe(realpathSync("/var/tmp"));
|
|
expect(agentTemporaryParent(false)).toBe(realpathSync(os.tmpdir()));
|
|
});
|
|
|
|
it("never hides the agent's own state or the checkout root, and only warns outside CI", () => {
|
|
const config = agentFilesystemSandboxConfig({
|
|
...base,
|
|
env: { RUNNER_TEMP: "/tmp" },
|
|
temporaryRoot: "/tmp/paperclip-runner-e2e-abc",
|
|
privateDir: "/tmp/paperclip-runner-e2e-abc/artifacts-private",
|
|
evidenceRoot: "/work",
|
|
});
|
|
expect(config).toEqual({ hidden: ["/work/paperclip/tests", "/work/paperclip/.git", "/work/paperclip/.manual-private-trusted"], required: false });
|
|
});
|
|
|
|
it.each([
|
|
["macOS", { platform: "darwin" as const }],
|
|
["an installed release", { installedRelease: true }],
|
|
["remote-only cells", { executions: [cell("rolling-web-deployment.runner-opencode.daytona.recover-controller")] }],
|
|
["legacy adapters", { executions: [cell("blocker-guidance.legacy-codex.local.human-authority")] }],
|
|
["Codex's own mount sandbox", { executions: [opencodeLocal, cell("necessary-question.runner-codex.local.necessary-free-text")] }],
|
|
])("does not apply to %s", (_label, override) => {
|
|
expect(agentFilesystemSandboxConfig({ ...base, ...override })).toBeNull();
|
|
});
|
|
|
|
it("round-trips through the server environment and rejects malformed values", () => {
|
|
const config = agentFilesystemSandboxConfig(base)!;
|
|
expect(parseAgentFilesystemSandboxConfig(JSON.stringify(config))).toEqual(config);
|
|
expect(parseAgentFilesystemSandboxConfig(undefined)).toBeNull();
|
|
expect(() => parseAgentFilesystemSandboxConfig(JSON.stringify({ hidden: ["relative"], required: true }))).toThrow(/malformed/);
|
|
});
|
|
});
|
|
|
|
describe("runnerd launch rewriting", () => {
|
|
it("wraps only the absolute runnerd executable and execs it with the original argv", () => {
|
|
const runnerd = "/work/paperclip/packages/paperclip-runner/runner/target/debug/paperclip-runnerd";
|
|
expect(isRunnerdLaunch(runnerd)).toBe(true);
|
|
expect(isRunnerdLaunch("paperclip-runnerd")).toBe(true);
|
|
expect(isRunnerdLaunch("/usr/bin/git")).toBe(false);
|
|
const invocation = sandboxedInvocation({ hidden: ["/work/paperclip/tests"], required: true }, "/usr/bin/python3", runnerd, ["--run-id", "r"], {});
|
|
expect(invocation).toEqual({
|
|
command: "/usr/bin/python3",
|
|
args: ["-I", "-S", agentFilesystemSandboxHelper, "--required", "--unset", "LC_CTYPE", "--hide", "/work/paperclip/tests", "--", runnerd, "--run-id", "r"],
|
|
});
|
|
expect(sandboxedInvocation({ hidden: [], required: false }, "p", runnerd, [], { LC_CTYPE: "C" }).args).toContain("LC_CTYPE=C");
|
|
});
|
|
|
|
it("rewrites runnerd launches through the wrapped spawn and passes other launches through", () => {
|
|
const calls: unknown[][] = [];
|
|
const fake = ((...args: unknown[]) => { calls.push(args); return { pid: 7 }; }) as unknown as typeof import("node:child_process").spawn;
|
|
const spawn = wrapRunnerdSpawn(fake, { hidden: ["/work/paperclip/tests"], required: true }, "/usr/bin/python3");
|
|
const runnerd = "/work/paperclip/packages/paperclip-runner/runner/target/debug/paperclip-runnerd";
|
|
spawn(runnerd, ["--run-id", "r"], { cwd: "/work", env: { LC_CTYPE: "C.UTF-8" }, detached: true });
|
|
spawn("/usr/bin/git", ["status"], { cwd: "/work" });
|
|
expect(calls[0]).toEqual(["/usr/bin/python3", expect.arrayContaining(["--hide", "/work/paperclip/tests", "--", runnerd, "--run-id", "r"]),
|
|
{ cwd: "/work", env: { LC_CTYPE: "C.UTF-8" }, detached: true }]);
|
|
expect(calls[1]).toEqual(["/usr/bin/git", ["status"], { cwd: "/work" }]);
|
|
});
|
|
|
|
it("rewrites runnerd for every direct launch API and refuses a shell launch", () => {
|
|
const calls: unknown[][] = [];
|
|
const fake = (...args: unknown[]) => { calls.push(args); return { pid: 9 }; };
|
|
const config = { hidden: ["/work/paperclip/tests"], required: true };
|
|
const callback = () => undefined;
|
|
wrapRunnerdLaunch(fake, config, "/usr/bin/python3", "execFile")("paperclip-runnerd", ["--x"], { cwd: "/w" }, callback);
|
|
wrapRunnerdLaunch(fake, config, "/usr/bin/python3", "spawnSync")("/r/paperclip-runnerd", { cwd: "/w" });
|
|
expect(calls[0]).toEqual(["/usr/bin/python3", expect.arrayContaining(["--", "paperclip-runnerd", "--x"]), { cwd: "/w" }, callback]);
|
|
expect(calls[1]).toEqual(["/usr/bin/python3", expect.arrayContaining(["--", "/r/paperclip-runnerd"]), { cwd: "/w" }]);
|
|
expect(() => wrapRunnerdLaunch(fake, config, "/usr/bin/python3")("/r/paperclip-runnerd", [], { shell: true })).toThrow(/refusing/);
|
|
expect(RUNNERD_LAUNCH_APIS).toEqual(["spawn", "spawnSync", "execFile", "execFileSync"]);
|
|
});
|
|
|
|
it("keeps promisify(execFile) resolving { stdout, stderr } after wrapping", async () => {
|
|
const { execFile } = await import("node:child_process");
|
|
const { promisify } = await import("node:util");
|
|
const wrapped = wrapRunnerdLaunch(execFile, { hidden: ["/nowhere"], required: false }, "/usr/bin/python3", "execFile");
|
|
const result = await promisify(wrapped)(process.execPath, ["-e", "process.stdout.write('ok')"]);
|
|
expect(result).toEqual({ stdout: "ok", stderr: "" });
|
|
});
|
|
|
|
it("hides a linked worktree's gitdir and the shared object store", async () => {
|
|
const root = await realpath(await mkdtemp(path.join(os.tmpdir(), "agent-sandbox-git-")));
|
|
try {
|
|
const common = path.join(root, "main", ".git");
|
|
const gitDir = path.join(common, "worktrees", "wt");
|
|
await mkdir(gitDir, { recursive: true });
|
|
await writeFile(path.join(gitDir, "commondir"), "../..\n");
|
|
const checkout = path.join(root, "wt");
|
|
await mkdir(checkout);
|
|
await writeFile(path.join(checkout, ".git"), `gitdir: ${gitDir}\n`);
|
|
expect(gitStorePaths(checkout)).toEqual([path.join(checkout, ".git"), gitDir, common]);
|
|
expect(gitStorePaths(path.join(root, "main"))).toEqual([common]);
|
|
} finally {
|
|
await rm(root, { recursive: true, force: true });
|
|
}
|
|
});
|
|
|
|
it("installs the sandbox in the E2E server entry before the product starts", async () => {
|
|
const entry = await readFile(path.join(import.meta.dirname, "server-entry.ts"), "utf8");
|
|
const install = entry.indexOf("installAgentFilesystemSandbox(");
|
|
expect(install).toBeGreaterThan(0);
|
|
expect(install).toBeLessThan(entry.indexOf('await import("../../cli/src/index.js")'));
|
|
});
|
|
});
|
|
|
|
const landlock = process.platform === "linux" && (() => {
|
|
const probe = mkdtempSync(path.join(os.tmpdir(), "agent-sandbox-abi-"));
|
|
try {
|
|
execFileSync(pythonExecutable(), ["-I", "-S", agentFilesystemSandboxHelper, "--required", "--hide", probe, "--", "/bin/true"]);
|
|
return true;
|
|
} catch {
|
|
return false;
|
|
} finally {
|
|
rmSync(probe, { recursive: true, force: true });
|
|
}
|
|
})();
|
|
|
|
describe.skipIf(!landlock)("Landlock agent sandbox on this host", () => {
|
|
const roots: string[] = [];
|
|
afterEach(async () => { await Promise.all(roots.splice(0).map((root) => rm(root, { recursive: true, force: true }))); });
|
|
|
|
it("denies a sandboxed process the harness while keeping the product and temporary files usable", async () => {
|
|
const root = await realpath(await mkdtemp(path.join(os.tmpdir(), "agent-sandbox-")));
|
|
roots.push(root);
|
|
const repository = path.join(root, "checkout");
|
|
await mkdir(path.join(repository, "tests", "runner-e2e", "chat-scenarios"), { recursive: true });
|
|
await mkdir(path.join(repository, "packages", "paperclip-runner"), { recursive: true });
|
|
await mkdir(path.join(root, "scratch"));
|
|
await writeFile(path.join(repository, "tests", "runner-e2e", "agent-filesystem-sandbox.ts"), "grader");
|
|
await writeFile(path.join(repository, "tests", "runner-e2e", "chat-scenarios", "access.yaml"), "expected_outcome: secret");
|
|
await writeFile(path.join(repository, "packages", "paperclip-runner", "package.json"), "{}");
|
|
const attempt = path.join(root, "attempt");
|
|
await mkdir(path.join(attempt, "artifacts-private"), { recursive: true });
|
|
await mkdir(path.join(attempt, "workspace"));
|
|
await writeFile(path.join(attempt, "artifacts-private", "server.log"), "secret");
|
|
const config = { hidden: [path.join(repository, "tests"), path.join(attempt, "artifacts-private"), path.join(attempt, "control")], required: true };
|
|
// The fixture lives under the shared temporary directory, so point mktemp at a granted sibling.
|
|
const probe = probeAgentFilesystemSandbox(config, repository, pythonExecutable(), { ...process.env, TMPDIR: path.join(root, "scratch") }, path.join(root, "no-playwright-cache"));
|
|
expect(probe.failures).toEqual([]);
|
|
expect(probe.result).toMatchObject({ playwrightDefaultCache: "denied", harnessFile: "denied", harnessDirectory: "denied", productFile: "readable", temporaryWrite: "allowed" });
|
|
// The exact read from the reported run: grep over the checkout's scenarios.
|
|
const invocation = sandboxedInvocation(config, pythonExecutable(), "/bin/sh", ["-c", `grep -rn expected_outcome ${repository}/tests; echo "exit=$?"`], process.env);
|
|
const output = execFileSync(invocation.command, invocation.args, { encoding: "utf8" });
|
|
expect(output).not.toContain("secret");
|
|
expect(output).toMatch(/exit=2/);
|
|
const attemptCheck = sandboxedInvocation(config, pythonExecutable(), "/bin/sh", ["-c", `cat ${attempt}/artifacts-private/server.log; ls ${attempt}/workspace >/dev/null && echo workspace=ok; mkdir ${attempt}/control 2>/dev/null || echo control=blocked`], process.env);
|
|
const attemptOutput = execFileSync(attemptCheck.command, attemptCheck.args, { encoding: "utf8" });
|
|
expect(attemptOutput).not.toContain("secret");
|
|
expect(attemptOutput).toContain("workspace=ok");
|
|
expect(attemptOutput).toContain("control=blocked");
|
|
});
|
|
});
|