The Open Framework for Building Agents
fix(sandbox): keep relative symlinks when copying sandbox templates (#5224)
Andrew Barbac3bbae47d45b
diff --git a/.changeset/sandbox-template-relative-symlinks.md b/.changeset/sandbox-template-relative-symlinks.mdnew file mode 100644index 000000000..1cb575862--- /dev/null+++ b/.changeset/sandbox-template-relative-symlinks.md@@ -0,0 +1,5 @@+---+"eve": patch+---++Relative symlinks in an agent's `sandbox/workspace/` files, in skill packages, and in sandbox templates now stay relative in build output and in each sandbox session. Before, eve rewrote them as absolute host paths: `just-bash` sessions rejected them with `EACCES ... resolves outside sandbox`, and they did not resolve inside Docker, microsandbox, or remote sandboxes.diff --git a/packages/eve/src/compiler/workspace-resources.integration.test.ts b/packages/eve/src/compiler/workspace-resources.integration.test.tsnew file mode 100644index 000000000..1146a8dde--- /dev/null+++ b/packages/eve/src/compiler/workspace-resources.integration.test.ts@@ -0,0 +1,46 @@+import { readlink, symlink } from "node:fs/promises";+import { join } from "node:path";++import { describe, expect, it } from "vitest";++import { compileAgent } from "#compiler/compile-agent.js";+import { useTemporaryAppRoots } from "#internal/testing/use-temporary-app-roots.js";+import { createDiskRuntimeCompiledArtifactsSource } from "#runtime/compiled-artifacts-source.js";+import { loadCompiledManifest } from "#runtime/loaders/manifest.js";++const createAppRoot = useTemporaryAppRoots();++describe("materializeWorkspaceResources", () => {+ it("keeps nested relative symlinks in workspace files and skill packages relative", async () => {+ const app = await createAppRoot("eve-workspace-resource-symlinks-", {+ files: {+ "agent/agent.mjs": 'export default { model: "openai/gpt-5.4" };',+ "agent/instructions.md": "Help with notes.",+ "agent/sandbox/workspace/data/notes.txt": "seed",+ "agent/skills/review/SKILL.md": [+ "---",+ "description: Review notes.",+ "---",+ "Read the guide before reviewing.",+ ].join("\n"),+ "agent/skills/review/references/guide.md": "guide",+ },+ });+ await symlink("notes.txt", join(app.agentRoot, "sandbox/workspace/data/current.txt"));+ await symlink("guide.md", join(app.agentRoot, "skills/review/references/latest.md"));++ const { paths } = await compileAgent({ startPath: app.appRoot });+ const manifest = await loadCompiledManifest({+ compiledArtifactsSource: createDiskRuntimeCompiledArtifactsSource(app.appRoot),+ });+ const resourceRoot = join(+ paths.compileDirectoryPath,+ manifest.workspaceResourceRoot.logicalPath,+ );++ expect(await readlink(join(resourceRoot, "workspace/data/current.txt"))).toBe("notes.txt");+ expect(await readlink(join(resourceRoot, "skills/review/references/latest.md"))).toBe(+ "guide.md",+ );+ });+});diff --git a/packages/eve/src/compiler/workspace-resources.ts b/packages/eve/src/compiler/workspace-resources.tsindex 678de2666..088e6c0d2 100644--- a/packages/eve/src/compiler/workspace-resources.ts+++ b/packages/eve/src/compiler/workspace-resources.ts@@ -132,7 +132,7 @@ async function materializeSkill(input: {const skillRoot = join(input.nodeRoot, RESOURCE_SKILLS_DIRECTORY, input.skill.name);if (input.skill.sourceKind === "skill-package") {- await cp(input.skill.rootPath, skillRoot, { recursive: true });+ await cp(input.skill.rootPath, skillRoot, { recursive: true, verbatimSymlinks: true });return;}@@ -161,8 +161,10 @@ async function copyDirectoryContents(input: {continue;}+ // Without verbatimSymlinks, cp rewrites nested relative links as absolute host paths.await cp(join(input.sourcePath, entry.name), join(input.targetPath, entry.name), {recursive: true,+ verbatimSymlinks: true,});}}diff --git a/packages/eve/src/execution/sandbox/bindings/just-bash.scenario.test.ts b/packages/eve/src/execution/sandbox/bindings/just-bash.scenario.test.tsindex a63e6dd2f..817bd69ae 100644--- a/packages/eve/src/execution/sandbox/bindings/just-bash.scenario.test.ts+++ b/packages/eve/src/execution/sandbox/bindings/just-bash.scenario.test.ts@@ -459,6 +459,29 @@ describe("just-bash provider", () => {expect(result.stdout.trim().split("\n")).toEqual(["/workspace/skills/weather.md"]);});+ it("keeps a relative symlink from preparation usable and private in each session", async () => {+ const appRoot = await createTemporaryCacheDirectory("relative-symlink");+ const provider = createJustBashProvider({+ async prepare(session) {+ const result = await session.run({+ command:+ "mkdir -p data && echo template > data/notes.txt && ln -s data/notes.txt current.txt",+ });+ expect(result.exitCode).toBe(0);+ },+ });+ await provider.prepare({ appRoot, seedFiles: [] });++ const alice = await provider.openSession({ appRoot, sandboxName: "session-alice" });+ const write = await alice.sandbox.run({+ command: "echo alice > current.txt && readlink current.txt && cat data/notes.txt",+ });+ expect(write).toMatchObject({ exitCode: 0, stdout: "data/notes.txt\nalice\n" });++ const bob = await provider.openSession({ appRoot, sandboxName: "session-bob" });+ await expect(bob.sandbox.readTextFile({ path: "current.txt" })).resolves.toBe("template\n");+ });+it("opens a prewarmed template after the app moves to a different root", async () => {const buildRoot = await createTemporaryCacheDirectory("build-root");const runtimeRoot = await createTemporaryCacheDirectory("runtime-root");diff --git a/packages/eve/src/execution/sandbox/bindings/local-provider-utils.integration.test.ts b/packages/eve/src/execution/sandbox/bindings/local-provider-utils.integration.test.tsnew file mode 100644index 000000000..f5c00294e--- /dev/null+++ b/packages/eve/src/execution/sandbox/bindings/local-provider-utils.integration.test.ts@@ -0,0 +1,27 @@+import { mkdir, readFile, readlink, symlink, writeFile } from "node:fs/promises";+import { join } from "node:path";++import { describe, expect, it } from "vitest";++import { copyDirectoryAtomically } from "#execution/sandbox/bindings/local-provider-utils.js";+import { useTemporaryDirectories } from "#internal/testing/use-temporary-app-roots.js";++const createScratchDirectory = useTemporaryDirectories();++describe("copyDirectoryAtomically", () => {+ it("keeps relative symlinks inside the copy instead of pointing them back at the template", async () => {+ const root = await createScratchDirectory("eve-sandbox-template-copy-");+ const templatePath = join(root, "template");+ const sessionPath = join(root, "session");+ await mkdir(join(templatePath, "data"), { recursive: true });+ await writeFile(join(templatePath, "data", "notes.txt"), "template");+ await symlink(join("data", "notes.txt"), join(templatePath, "current.txt"));++ await copyDirectoryAtomically(templatePath, sessionPath);+ await writeFile(join(sessionPath, "current.txt"), "session");++ expect(await readFile(join(templatePath, "data", "notes.txt"), "utf8")).toBe("template");+ expect(await readFile(join(sessionPath, "data", "notes.txt"), "utf8")).toBe("session");+ expect(await readlink(join(sessionPath, "current.txt"))).toBe(join("data", "notes.txt"));+ });+});diff --git a/packages/eve/src/execution/sandbox/bindings/local-provider-utils.ts b/packages/eve/src/execution/sandbox/bindings/local-provider-utils.tsindex 6e3f7ee98..0c1597b12 100644--- a/packages/eve/src/execution/sandbox/bindings/local-provider-utils.ts+++ b/packages/eve/src/execution/sandbox/bindings/local-provider-utils.ts@@ -73,7 +73,8 @@ export async function copyDirectoryAtomically(await rm(temporaryTargetPath, { force: true, recursive: true });await mkdir(dirname(targetPath), { recursive: true });try {- await cp(sourcePath, temporaryTargetPath, { recursive: true });+ // Without verbatimSymlinks, cp rewrites relative links as absolute paths into the source tree.+ await cp(sourcePath, temporaryTargetPath, { recursive: true, verbatimSymlinks: true });await rename(temporaryTargetPath, targetPath);} catch (error) {await rm(temporaryTargetPath, { force: true, recursive: true }).catch(() => {});