Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

refactor(sandbox): simplify resource shaping and remove dead sandbox code (#5230)

Andrew Barba7f1e5d32bfa6
diff --git a/packages/eve/src/execution/sandbox/bindings/docker.integration.test.ts b/packages/eve/src/execution/sandbox/bindings/docker.integration.test.ts
index de50b619a..bc54277d0 100644
--- a/packages/eve/src/execution/sandbox/bindings/docker.integration.test.ts
+++ b/packages/eve/src/execution/sandbox/bindings/docker.integration.test.ts
@@ -170,7 +170,6 @@ describe("Docker provider prewarm", () => {
await createEngine({ cli }).prepare({
appRoot,
- seedFiles: [],
});
expect(findCall(calls, (args) => args[0] === "build")?.args).toEqual([
@@ -200,7 +199,7 @@ describe("Docker provider prewarm", () => {
: undefined,
);
- await createEngine({ cli, options: { env } }).prepare({ appRoot, seedFiles: [] });
+ await createEngine({ cli, options: { env } }).prepare({ appRoot });
const runArgs = findCall(calls, (args) => args[0] === "run")?.args ?? [];
expect(runArgs.filter((arg) => arg.startsWith("AI_AGENT="))).toEqual([expected]);
@@ -225,7 +224,7 @@ describe("Docker provider prewarm", () => {
const result = await createEngine({ cli }).prepare({
appRoot,
- seedFiles: [{ content: "# Weather skill\n", path: "/workspace/skills/weather.md" }],
+ workspace: [{ content: "# Weather skill\n", relativePath: "skills/weather.md" }],
});
expect(result.imageReference).toMatch(/^eve-sandbox-template:/u);
@@ -296,7 +295,7 @@ describe("Docker provider prewarm", () => {
return undefined;
});
- const result = await createEngine({ cli }).prepare({ appRoot, seedFiles: [] });
+ const result = await createEngine({ cli }).prepare({ appRoot });
expect(result.imageReference).toBe(publishedReference);
expect(
calls.filter(({ args }) =>
@@ -320,7 +319,7 @@ describe("Docker provider prewarm", () => {
return undefined;
});
- await expect(createEngine({ cli }).prepare({ appRoot, seedFiles: [] })).rejects.toThrow(
+ await expect(createEngine({ cli }).prepare({ appRoot })).rejects.toThrow(
/Failed to commit sandbox template image .*: disk full/u,
);
expect(committedReference).toMatch(/^eve-sandbox-template:/u);
@@ -346,7 +345,6 @@ describe("Docker provider prewarm", () => {
resourcesKey: "resources-hash",
resourcesPath,
appRoot,
- seedFiles: [],
});
const run = findCall(calls, (args) => args[0] === "run");
@@ -375,7 +373,6 @@ describe("Docker provider prewarm", () => {
await expect(
createEngine({ cli }).prepare({
appRoot,
- seedFiles: [],
}),
).rejects.toThrow(DockerDaemonUnavailableError);
});
diff --git a/packages/eve/src/execution/sandbox/bindings/docker.scenario.test.ts b/packages/eve/src/execution/sandbox/bindings/docker.scenario.test.ts
index e814c52e8..f42359c81 100644
--- a/packages/eve/src/execution/sandbox/bindings/docker.scenario.test.ts
+++ b/packages/eve/src/execution/sandbox/bindings/docker.scenario.test.ts
@@ -14,9 +14,7 @@ describe("docker CLI resolution", () => {
const appRoot = await createScratchDirectory("eve-docker-missing-");
const engine = createSandboxProviderHarness(createDockerSandboxProvider(), undefined);
- await expect(engine.prepare({ appRoot, seedFiles: [] })).rejects.toThrow(
- DockerUnavailableError,
- );
+ await expect(engine.prepare({ appRoot })).rejects.toThrow(DockerUnavailableError);
} finally {
vi.unstubAllEnvs();
}
diff --git a/packages/eve/src/execution/sandbox/bindings/docker.ts b/packages/eve/src/execution/sandbox/bindings/docker.ts
index 6a7eac926..d66237cdc 100644
--- a/packages/eve/src/execution/sandbox/bindings/docker.ts
+++ b/packages/eve/src/execution/sandbox/bindings/docker.ts
@@ -297,7 +297,6 @@ export function createDockerSandboxProvider(
);
await hydrateSandboxProviderResources({
- copySkills: true,
log: context.log,
resources: context.resources,
session: templateSession,
diff --git a/packages/eve/src/execution/sandbox/bindings/immutable-resources.test.ts b/packages/eve/src/execution/sandbox/bindings/immutable-resources.test.ts
index b6316d9a4..ae0d441e6 100644
--- a/packages/eve/src/execution/sandbox/bindings/immutable-resources.test.ts
+++ b/packages/eve/src/execution/sandbox/bindings/immutable-resources.test.ts
@@ -1,30 +1,20 @@
import { describe, expect, it, vi } from "vitest";
-import { hydrateSandboxFromImmutableResources } from "#execution/sandbox/bindings/immutable-resources.js";
+import { hydrateSandboxProviderResources } from "#execution/sandbox/bindings/immutable-resources.js";
-describe("hydrateSandboxFromImmutableResources", () => {
- it("copies workspace seed files and links skills to the read-only mount", async () => {
+describe("hydrateSandboxProviderResources", () => {
+ it("copies materialized workspace and skills so the prepared image keeps them without the mount", async () => {
const run = vi.fn(async (_input: { readonly command: string }) => ({
exitCode: 0,
stderr: "",
stdout: "",
}));
- await hydrateSandboxFromImmutableResources({ run } as never);
+ await hydrateSandboxProviderResources({
+ resources: { source: { key: "resources", kind: "materialized", path: "/compiled" } },
+ session: { run } as never,
+ });
const command = run.mock.calls[0]?.[0].command ?? "";
expect(command).toContain("cp -a /eve/resources/workspace/. /workspace/");
- expect(command).toContain('ln -s /eve/resources/skills "$HOME/.agents/skills"');
- expect(command).not.toContain("cp -a /eve/resources/skills");
- });
-
- it("copies skills when the prepared image must retain them without the mount", async () => {
- const run = vi.fn(async (_input: { readonly command: string }) => ({
- exitCode: 0,
- stderr: "",
- stdout: "",
- }));
- await hydrateSandboxFromImmutableResources({ run } as never, true);
- const command = run.mock.calls[0]?.[0].command ?? "";
expect(command).toContain('cp -a /eve/resources/skills/. "$HOME/.agents/skills/"');
- expect(command).not.toContain("ln -s /eve/resources/skills");
});
});
diff --git a/packages/eve/src/execution/sandbox/bindings/immutable-resources.ts b/packages/eve/src/execution/sandbox/bindings/immutable-resources.ts
index 6c09830cb..c9113052a 100644
--- a/packages/eve/src/execution/sandbox/bindings/immutable-resources.ts
+++ b/packages/eve/src/execution/sandbox/bindings/immutable-resources.ts
@@ -32,7 +32,6 @@ export async function prepareImmutableResources(input: {
}
export async function hydrateSandboxProviderResources(input: {
- readonly copySkills?: boolean;
readonly log?: (message: string) => void;
readonly resources: SandboxProviderResources;
readonly session: SandboxSession;
@@ -44,21 +43,12 @@ export async function hydrateSandboxProviderResources(input: {
return;
case "materialized":
input.log?.("hydrating workspace and skills from read-only resources");
- await hydrateSandboxFromImmutableResources(input.session, input.copySkills);
+ await hydrateSandboxFromImmutableResources(input.session);
return;
}
}
-export async function hydrateSandboxFromImmutableResources(
- session: SandboxSession,
- copySkills = false,
-): Promise<void> {
- const hydrateSkills = copySkills
- ? [
- ' mkdir -p "$HOME/.agents/skills"',
- ` cp -a ${SANDBOX_RESOURCES_ROOT}/skills/. "$HOME/.agents/skills/"`,
- ]
- : [` ln -s ${SANDBOX_RESOURCES_ROOT}/skills "$HOME/.agents/skills"`];
+async function hydrateSandboxFromImmutableResources(session: SandboxSession): Promise<void> {
const result = await session.run({
command: [
"set -e",
@@ -66,7 +56,8 @@ export async function hydrateSandboxFromImmutableResources(
`if [ -d ${SANDBOX_RESOURCES_ROOT}/skills ]; then`,
' mkdir -p "$HOME/.agents"',
' rm -rf "$HOME/.agents/skills"',
- ...hydrateSkills,
+ ' mkdir -p "$HOME/.agents/skills"',
+ ` cp -a ${SANDBOX_RESOURCES_ROOT}/skills/. "$HOME/.agents/skills/"`,
"fi",
].join("\n"),
});
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.ts
index 817bd69ae..8d155942d 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
@@ -37,7 +37,6 @@ async function createPrewarmedLocalHandle(input: {
const provider = createJustBashProvider();
await provider.prepare({
appRoot: input.appRoot,
- seedFiles: [],
});
return await provider.openSession({
appRoot: input.appRoot,
@@ -133,7 +132,7 @@ describe("just-bash sandbox file API", () => {
await provider.prepare({
appRoot,
- seedFiles: [{ content: "from template", path: "/workspace/seed.txt" }],
+ workspace: [{ content: "from template", relativePath: "seed.txt" }],
});
expect(factoryCalls).toBe(0);
@@ -286,7 +285,6 @@ describe("just-bash sandbox file API", () => {
await provider.prepare({
appRoot,
- seedFiles: [],
});
const { handle: firstHandle, state } = await provider.start({
@@ -318,7 +316,7 @@ describe("just-bash sandbox file API", () => {
it("removes the session root by key at session end, so the next start is fresh", async () => {
const appRoot = await createTemporaryCacheDirectory("session-end");
const provider = createJustBashProvider();
- await provider.prepare({ appRoot, seedFiles: [] });
+ await provider.prepare({ appRoot });
const session = { appRoot, sandboxName: "session-end" };
const { handle } = await provider.start(session);
await handle.sandbox.writeTextFile({ content: "left behind", path: "left.txt" });
@@ -440,10 +438,10 @@ describe("just-bash provider", () => {
await provider.prepare({
appRoot,
- seedFiles: [
+ workspace: [
{
content: "# Weather skill\n",
- path: "/workspace/skills/weather.md",
+ relativePath: "skills/weather.md",
},
],
});
@@ -470,7 +468,7 @@ describe("just-bash provider", () => {
expect(result.exitCode).toBe(0);
},
});
- await provider.prepare({ appRoot, seedFiles: [] });
+ await provider.prepare({ appRoot });
const alice = await provider.openSession({ appRoot, sandboxName: "session-alice" });
const write = await alice.sandbox.run({
@@ -489,10 +487,10 @@ describe("just-bash provider", () => {
const prepared = await provider.prepare({
appRoot: buildRoot,
- seedFiles: [
+ workspace: [
{
content: "# Weather skill\n",
- path: "/workspace/skills/weather.md",
+ relativePath: "skills/weather.md",
},
],
});
@@ -518,7 +516,6 @@ describe("just-bash provider", () => {
await provider.prepare({
appRoot,
- seedFiles: [],
});
const { handle: initialHandle, state: initialState } = await provider.start({
@@ -530,10 +527,10 @@ describe("just-bash provider", () => {
await provider.prepare({
appRoot,
- seedFiles: [
+ workspace: [
{
content: "# Weather skill\n",
- path: "/workspace/skills/weather.md",
+ relativePath: "skills/weather.md",
},
],
});
diff --git a/packages/eve/src/execution/sandbox/bindings/vercel.test.ts b/packages/eve/src/execution/sandbox/bindings/vercel.test.ts
index 0ffa00264..b188e70bb 100644
--- a/packages/eve/src/execution/sandbox/bindings/vercel.test.ts
+++ b/packages/eve/src/execution/sandbox/bindings/vercel.test.ts
@@ -235,7 +235,6 @@ async function createTestVercelSession() {
await provider.prepare({
appRoot: "/tmp/test-app-root",
- seedFiles: [],
});
const handle = await provider.openSession({
appRoot: "/tmp/test-app-root",
@@ -317,7 +316,7 @@ describe("createVercelSandbox", () => {
loadSandboxModule: async () => sandboxModule as never,
});
- await provider.prepare({ appRoot: "/tmp/test-app-root", seedFiles: [] });
+ await provider.prepare({ appRoot: "/tmp/test-app-root" });
await provider.openSession({
appRoot: "/tmp/test-app-root",
prepared: { snapshotId: "prepared-snapshot" },
@@ -394,7 +393,6 @@ describe("createVercelSandbox", () => {
await provider.prepare({
appRoot: "/tmp/test-app-root",
- seedFiles: [],
});
expect(sandboxModule.Sandbox.create).toHaveBeenCalledWith(
@@ -418,7 +416,6 @@ describe("createVercelSandbox", () => {
await provider.prepare({
appRoot: "/tmp/test-app-root",
- seedFiles: [],
});
expect(sandboxModule.Sandbox.create).toHaveBeenCalledWith(
@@ -453,7 +450,6 @@ describe("createVercelSandbox", () => {
await expect(
provider.prepare({
appRoot: "/tmp/test-app-root",
- seedFiles: [],
}),
).rejects.toThrow(/The sandbox request is invalid/);
});
@@ -537,25 +533,15 @@ describe("createVercelSandbox", () => {
await provider.prepare({
appRoot: "/tmp/test-app-root",
- seedFiles: [
- {
- content: "skill body",
- path: "/workspace/skills/weather/SKILL.md",
- },
- {
- content: Buffer.from([0, 1, 2, 3]),
- path: "/workspace/assets/fixture.bin",
- },
- {
- content: "model skill body",
- path: "$HOME/.agents/skills/research/SKILL.md",
- },
+ skills: [{ content: "model skill body", relativePath: "research/SKILL.md" }],
+ workspace: [
+ { content: "skill body", relativePath: "skills/weather/SKILL.md" },
+ { content: Buffer.from([0, 1, 2, 3]), relativePath: "assets/fixture.bin" },
],
});
await provider.prepare({
appRoot: "/tmp/test-app-root",
- seedFiles: [],
});
await provider.openSession({
@@ -592,7 +578,6 @@ describe("createVercelSandbox", () => {
await provider.prepare({
appRoot: "/tmp/test-app-root",
- seedFiles: [],
});
const handle = await provider.openSession({
appRoot: "/tmp/test-app-root",
@@ -627,7 +612,6 @@ describe("createVercelSandbox", () => {
await provider.prepare({
appRoot: "/tmp/test-app-root",
- seedFiles: [],
});
await provider.openSession({
@@ -879,7 +863,7 @@ describe("createVercelSandbox", () => {
await createTestVercelSandbox({
loadSandboxModule: async () => sandboxModule as never,
prepare,
- }).prepare({ appRoot: "/tmp/test-app-root", seedFiles: [] });
+ }).prepare({ appRoot: "/tmp/test-app-root" });
/** The build-private sandboxes: everything a build created except the template pointer. */
const privateSandboxes = (fake: ReturnType<typeof createFakeVercelProvider>) =>
@@ -1115,7 +1099,7 @@ describe("createVercelSandbox", () => {
await createTestVercelSandbox({
createOptions: { tags: { team: "x" } },
loadSandboxModule: async () => fake.sandboxModule as never,
- }).prepare({ appRoot: "/tmp/test-app-root", seedFiles: [] });
+ }).prepare({ appRoot: "/tmp/test-app-root" });
expect(fake.pointer()?.tags).toEqual({ team: "x" });
});
@@ -1153,7 +1137,6 @@ describe("createVercelSandbox", () => {
await provider.prepare({
appRoot: "/tmp/test-app-root",
- seedFiles: [],
});
await provider.openSession({
@@ -1256,7 +1239,6 @@ describe("createVercelSandbox", () => {
});
await provider.prepare({
appRoot: "/tmp/test-app-root",
- seedFiles: [],
});
const handle = await provider.openSession({
appRoot: "/tmp/test-app-root",
@@ -1293,7 +1275,6 @@ describe("createVercelSandbox", () => {
});
await provider.prepare({
appRoot: "/tmp/test-app-root",
- seedFiles: [],
});
const handle = await provider.openSession({
appRoot: "/tmp/test-app-root",
@@ -1376,7 +1357,6 @@ describe("createVercelSandbox", () => {
await provider.prepare({
appRoot: "/tmp/test-app-root",
- seedFiles: [],
});
const handle = await provider.openSession({
@@ -1420,7 +1400,6 @@ describe("createVercelSandbox", () => {
await provider.prepare({
appRoot: "/tmp/test-app-root",
- seedFiles: [],
});
const handle = await provider.openSession({
@@ -1506,7 +1485,6 @@ describe("createVercelSandbox", () => {
await provider.prepare({
appRoot: "/tmp/test-app-root",
- seedFiles: [],
});
const handle = await provider.openSession({
appRoot: "/tmp/test-app-root",
@@ -1625,7 +1603,6 @@ describe("createVercelSandbox", () => {
await provider.prepare({
appRoot: "/tmp/test-app-root",
- seedFiles: [],
});
await provider.openSession({
@@ -1683,7 +1660,6 @@ describe("createVercelSandbox", () => {
await provider.prepare({
appRoot: "/tmp/test-app-root",
- seedFiles: [],
});
expect(templateSandbox.runCommand).toHaveBeenCalledTimes(2);
@@ -1725,7 +1701,6 @@ describe("createVercelSandbox", () => {
const prewarm = provider.prepare({
appRoot: "/tmp/test-app-root",
- seedFiles: [],
});
await expect(prewarm).rejects.toThrow(/Failed to initialize Vercel sandbox base runtime/);
diff --git a/packages/eve/src/execution/sandbox/ensure.ts b/packages/eve/src/execution/sandbox/ensure.ts
index 4bfe2ffcb..5929b33a6 100644
--- a/packages/eve/src/execution/sandbox/ensure.ts
+++ b/packages/eve/src/execution/sandbox/ensure.ts
@@ -19,7 +19,7 @@ import {
type RuntimeCompiledArtifactsSource,
} from "#runtime/compiled-artifacts-source.js";
import { loadSandboxPreparedArtifact } from "#runtime/sandbox/prepared-artifacts.js";
-import type { RuntimeSandboxRegistry } from "#runtime/sandbox/registry.js";
+import { owningSandboxDefinition, type RuntimeSandboxRegistry } from "#runtime/sandbox/registry.js";
import {
isRetiredSandboxSessionState,
type SandboxAccess,
@@ -111,6 +111,7 @@ export async function ensureSandboxAccess(
getRuntimeCompiledArtifactsSandboxAppRoot(input.compiledArtifactsSource) ?? process.cwd();
const captured = (): SandboxState => ({ session: persisted });
const registered = input.registry.sandbox;
+ // Production always registers a sandbox; test runtimes without one cast a null registry.
if (registered === null) {
return {
async captureState() {
@@ -126,6 +127,8 @@ export async function ensureSandboxAccess(
async stop() {},
};
}
+ const ownerDefinition = owningSandboxDefinition(registered);
+ const ownerNodeId = registered.inheritance?.nodeId ?? input.nodeId;
function providerContext(turnId: string): SandboxProviderSessionContext {
const activeSession =
@@ -144,25 +147,23 @@ export async function ensureSandboxAccess(
}
function activeDefinition() {
- const definition = registered.inheritance?.definition ?? registered.definition;
- if (definition.kind !== "independent")
+ if (ownerDefinition.kind !== "independent")
throw new Error(
- `Sandbox "${definition.logicalPath}" uses defineParentSandbox(), but this agent has no parent sandbox to share. ` +
+ `Sandbox "${ownerDefinition.logicalPath}" uses defineParentSandbox(), but this agent has no parent sandbox to share. ` +
"Only a declared subagent can share its parent's sandbox. Give this agent its own sandbox with defineSandbox() and an exported environment.",
);
- return definition;
+ return ownerDefinition;
}
async function loadArtifact(provider: SandboxProviderRuntime) {
- const artifactNodeId = registered.inheritance?.nodeId ?? input.nodeId;
const artifact = await loadSandboxPreparedArtifact({
compiledArtifactsSource: input.compiledArtifactsSource,
- nodeId: artifactNodeId,
+ nodeId: ownerNodeId,
providerName: provider.providerName,
});
if (artifact === undefined) {
throw new SandboxTemplateNotProvisionedError({
- nodeId: artifactNodeId,
+ nodeId: ownerNodeId,
providerName: provider.providerName,
});
}
@@ -269,7 +270,7 @@ export async function ensureSandboxAccess(
if (isEveDevEnvironment() && input.compiledArtifactsSource.kind === "disk") {
await ensureDevelopmentSandboxesPrepared({
compiledArtifactsSource: input.compiledArtifactsSource,
- nodeId: registered.inheritance?.nodeId ?? input.nodeId,
+ nodeId: ownerNodeId,
providerName: getSandboxEnvironmentRuntime(definition.environment).providerName,
});
}
@@ -290,11 +291,7 @@ export async function ensureSandboxAccess(
}
// Apps hosted in one process can reuse a node id and a tool session id.
- const startKey = [
- appRoot,
- registered.inheritance?.nodeId ?? input.nodeId,
- input.sessionId,
- ].join("\0");
+ const startKey = [appRoot, ownerNodeId, input.sessionId].join("\0");
// A failed start wakes every waiter at once; re-check so only one retries.
let concurrentStart = pendingSandboxStarts.get(startKey);
while (concurrentStart !== undefined) {
@@ -376,10 +373,8 @@ export async function ensureSandboxAccess(
return current;
}
- const definition = registered.inheritance?.definition ?? registered.definition;
-
return {
- environment: definition.kind === "independent" ? definition.environment : undefined,
+ environment: ownerDefinition.kind === "independent" ? ownerDefinition.environment : undefined,
async captureState() {
if (opening !== undefined) await opening;
return captured();
diff --git a/packages/eve/src/execution/sandbox/prewarm.test.ts b/packages/eve/src/execution/sandbox/prewarm.test.ts
index 61a40ee72..c040c6ef7 100644
--- a/packages/eve/src/execution/sandbox/prewarm.test.ts
+++ b/packages/eve/src/execution/sandbox/prewarm.test.ts
@@ -15,9 +15,7 @@ import { defineSandbox } from "#public/definitions/sandbox.js";
import { resolveSandboxCacheDirectory } from "#internal/application/paths.js";
const mocks = vi.hoisted(() => ({
- materializeWorkspaceDirectory: vi.fn<
- (path: string) => Promise<readonly { readonly content: Buffer; readonly path: string }[]>
- >(async () => []),
+ materializeWorkspaceDirectory: vi.fn(async (_path: string) => ({ skills: [], workspace: [] })),
}));
vi.mock("#runtime/workspace/seed-files.js", () => ({
@@ -27,7 +25,7 @@ vi.mock("#runtime/workspace/seed-files.js", () => ({
describe("prewarmAppSandboxes", () => {
afterEach(() => {
mocks.materializeWorkspaceDirectory.mockReset();
- mocks.materializeWorkspaceDirectory.mockResolvedValue([]);
+ mocks.materializeWorkspaceDirectory.mockResolvedValue({ skills: [], workspace: [] });
vi.unstubAllEnvs();
});
diff --git a/packages/eve/src/execution/sandbox/prewarm.ts b/packages/eve/src/execution/sandbox/prewarm.ts
index e416a8eb1..4eefbf675 100644
--- a/packages/eve/src/execution/sandbox/prewarm.ts
+++ b/packages/eve/src/execution/sandbox/prewarm.ts
@@ -7,6 +7,7 @@ import {
createSandboxProviderResources,
type SandboxPreparedArtifact,
type SandboxProviderPrepareContext,
+ type SandboxProviderResources,
type SandboxProviderRuntime,
} from "#shared/sandbox-provider.js";
import {
@@ -207,7 +208,7 @@ async function collectPrewarmTargets(input: {
"sandbox",
);
const provider = getSandboxEnvironmentRuntime(definition.environment);
- const seedFiles = await loadResourceRootSeedFiles({
+ const resources = await loadSandboxProviderResources({
compileDirectoryPath: input.compileDirectoryPath,
workspaceResourceRoot,
});
@@ -215,14 +216,7 @@ async function collectPrewarmTargets(input: {
context: {
files: createSandboxProviderFiles(sandboxRoot),
host: createDevelopmentSandboxProviderHost(input.appRoot),
- resources: createSandboxProviderResources({
- resourcesKey: workspaceResourceRoot.contentHash,
- resourcesPath:
- workspaceResourceRoot.contentHash === undefined
- ? undefined
- : `${input.compileDirectoryPath}/${workspaceResourceRoot.logicalPath}`,
- seedFiles,
- }),
+ resources,
sourceRevision: definition.revisionHash,
storagePath: resolveSandboxCacheDirectory(input.appRoot),
},
@@ -238,27 +232,22 @@ async function collectPrewarmTargets(input: {
}
/**
- * Resolves the per-node compiled workspace resource root to an absolute
- * disk path under `.eve/compile/` and materializes its contents into the
- * `{path, content}` shape consumed by sandbox providers.
- *
- * Returns an empty array when the resource root descriptor advertises no
- * root entries (the materializer would emit no files anyway).
+ * Reads the node's compiled workspace resource root under `.eve/compile/`
+ * into the resource trees handed to the provider. A root without content has
+ * no resources.
*/
-async function loadResourceRootSeedFiles(input: {
+async function loadSandboxProviderResources(input: {
readonly compileDirectoryPath: string;
readonly workspaceResourceRoot: CompiledWorkspaceResourceRoot;
-}): Promise<readonly { readonly content: Uint8Array; readonly path: string }[]> {
- if (
- input.workspaceResourceRoot.contentHash === undefined &&
- input.workspaceResourceRoot.rootEntries.length === 0
- ) {
- return [];
- }
- const materialized = await materializeWorkspaceDirectory(
- `${input.compileDirectoryPath}/${input.workspaceResourceRoot.logicalPath}`,
- );
- return materialized.map((file) => ({ content: file.content, path: file.path }));
+}): Promise<SandboxProviderResources> {
+ const { contentHash, logicalPath } = input.workspaceResourceRoot;
+ if (contentHash === undefined) return createSandboxProviderResources({});
+ const path = `${input.compileDirectoryPath}/${logicalPath}`;
+ return createSandboxProviderResources({
+ key: contentHash,
+ path,
+ ...(await materializeWorkspaceDirectory(path)),
+ });
}
async function loadGraphFromArtifacts(input: {
diff --git a/packages/eve/src/execution/session/handoff-steps.ts b/packages/eve/src/execution/session/handoff-steps.ts
index def05d10d..130d5d310 100644
--- a/packages/eve/src/execution/session/handoff-steps.ts
+++ b/packages/eve/src/execution/session/handoff-steps.ts
@@ -41,6 +41,7 @@ import {
EVE_VERSION_ATTRIBUTE,
} from "#execution/eve-workflow-attributes.js";
import { getResolvedRuntimeAgentNode } from "#runtime/graph.js";
+import { owningSandboxDefinition } from "#runtime/sandbox/registry.js";
import { isRetiredSandboxSessionState } from "#sandbox/state.js";
import { BundleKey } from "#runtime/sessions/runtime-context-keys.js";
import { getSandboxEnvironmentRuntime } from "#shared/sandbox-environment.js";
@@ -198,10 +199,9 @@ export async function prepareSuccessorStep(input: {
sandboxState !== undefined &&
!isRetiredSandboxSessionState(sandboxState)
) {
- const definition =
- getResolvedRuntimeAgentNode(bundle.graph, bundle.nodeId).sandboxRegistry.sandbox.inheritance
- ?.definition ??
- getResolvedRuntimeAgentNode(bundle.graph, bundle.nodeId).sandboxRegistry.sandbox.definition;
+ const definition = owningSandboxDefinition(
+ getResolvedRuntimeAgentNode(bundle.graph, bundle.nodeId).sandboxRegistry.sandbox,
+ );
if (definition.kind !== "independent") {
throw new Error("Session checkpoint sandbox has no resolved provider.");
}
diff --git a/packages/eve/src/execution/tool-session/sandbox.ts b/packages/eve/src/execution/tool-session/sandbox.ts
index 91ea1bea1..36c56bcbd 100644
--- a/packages/eve/src/execution/tool-session/sandbox.ts
+++ b/packages/eve/src/execution/tool-session/sandbox.ts
@@ -1,4 +1,8 @@
-import type { RuntimeSandboxRegistry } from "#runtime/sandbox/registry.js";
+import {
+ owningSandboxDefinition,
+ type RuntimeRegisteredSandbox,
+ type RuntimeSandboxRegistry,
+} from "#runtime/sandbox/registry.js";
import { getSandboxEnvironmentRuntime } from "#shared/sandbox-environment.js";
import type { SandboxProviderHandle, SandboxProviderRuntime } from "#shared/sandbox-provider.js";
@@ -63,8 +67,9 @@ export async function releaseToolSessionHandle(
}
function registeredProvider(registry: RuntimeSandboxRegistry): SandboxProviderRuntime | undefined {
- const registered = registry.sandbox;
- const definition = registered?.inheritance?.definition ?? registered?.definition;
+ // Test runtimes without a sandbox cast a null registry.
+ const registered = registry.sandbox as RuntimeRegisteredSandbox | null | undefined;
+ const definition = registered ? owningSandboxDefinition(registered) : undefined;
if (definition?.kind !== "independent") return undefined;
return getSandboxEnvironmentRuntime(definition.environment);
}
diff --git a/packages/eve/src/internal/testing/sandbox-provider-harness.ts b/packages/eve/src/internal/testing/sandbox-provider-harness.ts
index b7a87c484..94e524a6b 100644
--- a/packages/eve/src/internal/testing/sandbox-provider-harness.ts
+++ b/packages/eve/src/internal/testing/sandbox-provider-harness.ts
@@ -5,6 +5,7 @@ import {
type SandboxPreparedArtifact,
type SandboxProviderHandle,
type SandboxProviderImplementation,
+ type SandboxProviderResourceFile,
} from "#shared/sandbox-provider.js";
import type { SandboxSession } from "#shared/sandbox-session.js";
@@ -62,23 +63,20 @@ export function createSandboxProviderHarness<
readonly log?: (message: string) => void;
readonly resourcesKey?: string;
readonly resourcesPath?: string;
- readonly seedFiles?: readonly {
- readonly content: string | Uint8Array;
- readonly path: string;
- }[];
+ readonly skills?: readonly SandboxProviderResourceFile[];
readonly sourceRevision?: string;
+ readonly workspace?: readonly SandboxProviderResourceFile[];
}) {
+ const hasFiles = (input.skills?.length ?? 0) + (input.workspace?.length ?? 0) > 0;
const artifact = await implementation.prepare({
files: createSandboxProviderFiles(`${input.appRoot}/sandbox`),
host: createSandboxProviderHost(input.appRoot),
log: input.log,
resources: createSandboxProviderResources({
- ...input,
- resourcesKey:
- input.resourcesKey ??
- (input.seedFiles === undefined || input.seedFiles.length === 0
- ? undefined
- : "test-resources"),
+ key: input.resourcesKey ?? (hasFiles ? "test-resources" : undefined),
+ path: input.resourcesPath,
+ skills: input.skills,
+ workspace: input.workspace,
}),
sourceRevision: input.sourceRevision ?? "test-source-revision",
storagePath: input.appRoot,
diff --git a/packages/eve/src/runtime/sandbox/registry.ts b/packages/eve/src/runtime/sandbox/registry.ts
index 04be9f552..a1e8141f4 100644
--- a/packages/eve/src/runtime/sandbox/registry.ts
+++ b/packages/eve/src/runtime/sandbox/registry.ts
@@ -25,6 +25,13 @@ export interface RuntimeRegisteredSandbox {
};
}
+/** The definition that opens `sandbox`: its owner's for a subagent that shares its parent's sandbox. */
+export function owningSandboxDefinition(
+ sandbox: RuntimeRegisteredSandbox,
+): ResolvedSandboxDefinition {
+ return sandbox.inheritance?.definition ?? sandbox.definition;
+}
+
/**
* Runtime-owned registry that exposes the resolved sandbox to the harness
* startup path.
diff --git a/packages/eve/src/runtime/workspace/seed-files.scenario.test.ts b/packages/eve/src/runtime/workspace/seed-files.scenario.test.ts
new file mode 100644
index 000000000..69650c91c
--- /dev/null
+++ b/packages/eve/src/runtime/workspace/seed-files.scenario.test.ts
@@ -0,0 +1,73 @@
+import { mkdir, writeFile } from "node:fs/promises";
+import { dirname, join } from "node:path";
+
+import { describe, expect, it } from "vitest";
+
+import { useTemporaryDirectories } from "#internal/testing/use-temporary-app-roots.js";
+import { materializeWorkspaceDirectory } from "#runtime/workspace/seed-files.js";
+import {
+ createSandboxProviderResources,
+ providerResourceTargetFiles,
+} from "#shared/sandbox-provider.js";
+
+const createScratchDirectory = useTemporaryDirectories();
+
+describe("compiled resource root materialization", () => {
+ it("hands providers separate workspace and skill trees with stable target paths", async () => {
+ const resourceRoot = await createScratchDirectory("eve-resource-root-");
+ const files: Record<string, string> = {
+ "skills/research/SKILL.md": "research skill",
+ "skills/research/refs/sources.md": "sources",
+ "skills/weather/SKILL.md": "weather skill",
+ "workspace/README.md": "readme",
+ "workspace/data/a.csv": "a",
+ "workspace/data/b.csv": "b",
+ "workspace/notes.md": "notes",
+ };
+ for (const [path, content] of Object.entries(files)) {
+ await mkdir(dirname(join(resourceRoot, path)), { recursive: true });
+ await writeFile(join(resourceRoot, path), content);
+ }
+
+ const resources = createSandboxProviderResources({
+ key: "resources-hash",
+ path: resourceRoot,
+ ...(await materializeWorkspaceDirectory(resourceRoot)),
+ });
+
+ // Each tree is ordered by locale-aware relative path, not raw bytes.
+ expect(resources).toEqual({
+ skills: {
+ files: [
+ { content: Buffer.from("sources"), relativePath: "research/refs/sources.md" },
+ { content: Buffer.from("research skill"), relativePath: "research/SKILL.md" },
+ { content: Buffer.from("weather skill"), relativePath: "weather/SKILL.md" },
+ ],
+ key: "resources-hash:skills",
+ mountPath: "/eve/resources/skills",
+ targetPath: "$HOME/.agents/skills",
+ },
+ source: { key: "resources-hash", kind: "materialized", path: resourceRoot },
+ workspace: {
+ files: [
+ { content: Buffer.from("a"), relativePath: "data/a.csv" },
+ { content: Buffer.from("b"), relativePath: "data/b.csv" },
+ { content: Buffer.from("notes"), relativePath: "notes.md" },
+ { content: Buffer.from("readme"), relativePath: "README.md" },
+ ],
+ key: "resources-hash:workspace",
+ mountPath: "/eve/resources/workspace",
+ targetPath: "/workspace",
+ },
+ });
+ expect(providerResourceTargetFiles(resources).map((file) => file.path)).toEqual([
+ "/workspace/data/a.csv",
+ "/workspace/data/b.csv",
+ "/workspace/notes.md",
+ "/workspace/README.md",
+ "$HOME/.agents/skills/research/refs/sources.md",
+ "$HOME/.agents/skills/research/SKILL.md",
+ "$HOME/.agents/skills/weather/SKILL.md",
+ ]);
+ });
+});
diff --git a/packages/eve/src/runtime/workspace/seed-files.ts b/packages/eve/src/runtime/workspace/seed-files.ts
index af0c91bab..41b010ced 100644
--- a/packages/eve/src/runtime/workspace/seed-files.ts
+++ b/packages/eve/src/runtime/workspace/seed-files.ts
@@ -1,76 +1,57 @@
import { readdir, readFile } from "node:fs/promises";
import { join, posix as pathPosix } from "node:path";
-import { WORKSPACE_ROOT } from "#runtime/workspace/types.js";
-import { MODEL_SKILL_ROOT } from "#shared/skill-paths.js";
+import type { SandboxProviderResourceFile } from "#shared/sandbox-provider.js";
const RESOURCE_WORKSPACE_DIRECTORY = "workspace";
const RESOURCE_SKILLS_DIRECTORY = "skills";
-/**
- * One concrete file materialized from a workspace seed directory for
- * sandbox template preparation.
- */
-interface MaterializedWorkspaceFile {
- readonly content: Buffer;
- readonly path: string;
+/** The files of one resource directory, split into the trees sandbox providers receive. */
+export interface MaterializedResourceTrees {
+ readonly skills: readonly SandboxProviderResourceFile[];
+ readonly workspace: readonly SandboxProviderResourceFile[];
}
/**
- * Walks a directory tree on disk and returns one entry per file rooted at
- * `/workspace/...`, sorted by path. The directory is treated as the
- * `/workspace` root for the resulting seed file paths.
+ * Reads a compiled resource directory into its `workspace/` and `skills/`
+ * trees, each sorted by relative path. A directory with neither subdirectory
+ * is read as the workspace tree itself.
*/
export async function materializeWorkspaceDirectory(
sourceDirectoryPath: string,
-): Promise<readonly MaterializedWorkspaceFile[]> {
- const files: MaterializedWorkspaceFile[] = [];
+): Promise<MaterializedResourceTrees> {
const entries = await readdir(sourceDirectoryPath, {
withFileTypes: true,
});
- const workspaceEntry = entries.find(
- (entry) => entry.name === RESOURCE_WORKSPACE_DIRECTORY && entry.isDirectory(),
- );
- const skillsEntry = entries.find(
- (entry) => entry.name === RESOURCE_SKILLS_DIRECTORY && entry.isDirectory(),
- );
-
- if (workspaceEntry !== undefined || skillsEntry !== undefined) {
- if (workspaceEntry !== undefined) {
- await addMaterializedDirectoryFiles({
- files,
- logicalDirectoryPath: ".",
- sourceDirectoryPath: join(sourceDirectoryPath, RESOURCE_WORKSPACE_DIRECTORY),
- targetRoot: WORKSPACE_ROOT,
- });
- }
+ const hasDirectory = (name: string) =>
+ entries.some((entry) => entry.name === name && entry.isDirectory());
+ const hasWorkspace = hasDirectory(RESOURCE_WORKSPACE_DIRECTORY);
+ const hasSkills = hasDirectory(RESOURCE_SKILLS_DIRECTORY);
- if (skillsEntry !== undefined) {
- await addMaterializedDirectoryFiles({
- files,
- logicalDirectoryPath: ".",
- sourceDirectoryPath: join(sourceDirectoryPath, RESOURCE_SKILLS_DIRECTORY),
- targetRoot: MODEL_SKILL_ROOT,
- });
- }
- } else {
- await addMaterializedDirectoryFiles({
- files,
- logicalDirectoryPath: ".",
- sourceDirectoryPath,
- targetRoot: WORKSPACE_ROOT,
- });
+ if (!hasWorkspace && !hasSkills) {
+ return { skills: [], workspace: await readResourceTree(sourceDirectoryPath) };
}
+ return {
+ skills: hasSkills
+ ? await readResourceTree(join(sourceDirectoryPath, RESOURCE_SKILLS_DIRECTORY))
+ : [],
+ workspace: hasWorkspace
+ ? await readResourceTree(join(sourceDirectoryPath, RESOURCE_WORKSPACE_DIRECTORY))
+ : [],
+ };
+}
- files.sort((left, right) => left.path.localeCompare(right.path));
+async function readResourceTree(rootPath: string): Promise<SandboxProviderResourceFile[]> {
+ const files: SandboxProviderResourceFile[] = [];
+ await addResourceFiles({ files, relativeDirectoryPath: ".", sourceDirectoryPath: rootPath });
+ files.sort((left, right) => left.relativePath.localeCompare(right.relativePath));
return files;
}
-async function addMaterializedDirectoryFiles(input: {
- readonly files: MaterializedWorkspaceFile[];
- readonly logicalDirectoryPath: string;
+async function addResourceFiles(input: {
+ readonly files: SandboxProviderResourceFile[];
+ readonly relativeDirectoryPath: string;
readonly sourceDirectoryPath: string;
- readonly targetRoot: string;
}): Promise<void> {
const entries = await readdir(input.sourceDirectoryPath, {
withFileTypes: true,
@@ -82,21 +63,20 @@ async function addMaterializedDirectoryFiles(input: {
}
const sourcePath = join(input.sourceDirectoryPath, entry.name);
- const logicalPath = pathPosix.join(input.logicalDirectoryPath, entry.name);
+ const relativePath = pathPosix.join(input.relativeDirectoryPath, entry.name);
if (entry.isDirectory()) {
- await addMaterializedDirectoryFiles({
+ await addResourceFiles({
files: input.files,
- logicalDirectoryPath: logicalPath,
+ relativeDirectoryPath: relativePath,
sourceDirectoryPath: sourcePath,
- targetRoot: input.targetRoot,
});
continue;
}
input.files.push({
content: await readFile(sourcePath),
- path: pathPosix.join(input.targetRoot, logicalPath),
+ relativePath,
});
}
}
diff --git a/packages/eve/src/shared/sandbox-provider.ts b/packages/eve/src/shared/sandbox-provider.ts
index 768090226..26068209a 100644
--- a/packages/eve/src/shared/sandbox-provider.ts
+++ b/packages/eve/src/shared/sandbox-provider.ts
@@ -253,54 +253,26 @@ function eraseSandboxProviderImplementation<
}
export function createSandboxProviderResources(input: {
- readonly resourcesKey?: string;
- readonly resourcesPath?: string;
- readonly seedFiles?: readonly {
- readonly content: string | Uint8Array;
- readonly path: string;
- }[];
+ readonly key?: string;
+ readonly path?: string;
+ readonly skills?: readonly SandboxProviderResourceFile[];
+ readonly workspace?: readonly SandboxProviderResourceFile[];
}): SandboxProviderResources {
- if (input.resourcesKey === undefined) return { source: { kind: "none" } };
- const files = input.seedFiles ?? [];
- const source: SandboxProviderResourceSource =
- input.resourcesPath !== undefined
- ? { key: input.resourcesKey, kind: "materialized", path: input.resourcesPath }
- : { key: input.resourcesKey, kind: "inline" };
+ const { key, path } = input;
+ if (key === undefined) return { source: { kind: "none" } };
return {
- skills: createResourceTree({
- files: files.filter((file) => file.path.startsWith("$HOME/.agents/skills/")),
- key: `${input.resourcesKey}:skills`,
+ skills: {
+ files: input.skills ?? [],
+ key: `${key}:skills`,
mountPath: "/eve/resources/skills",
- prefix: "$HOME/.agents/skills/",
targetPath: "$HOME/.agents/skills",
- }),
- source,
- workspace: createResourceTree({
- files: files.filter((file) => !file.path.startsWith("$HOME/.agents/skills/")),
- key: `${input.resourcesKey}:workspace`,
+ },
+ source: path === undefined ? { key, kind: "inline" } : { key, kind: "materialized", path },
+ workspace: {
+ files: input.workspace ?? [],
+ key: `${key}:workspace`,
mountPath: "/eve/resources/workspace",
- prefix: "/workspace/",
targetPath: "/workspace",
- }),
- };
-}
-
-function createResourceTree(input: {
- readonly files: readonly { readonly content: string | Uint8Array; readonly path: string }[];
- readonly key: string;
- readonly mountPath: string;
- readonly prefix: string;
- readonly targetPath: string;
-}): SandboxProviderResourceTree {
- return {
- files: input.files.map((file) => ({
- content: file.content,
- relativePath: file.path.startsWith(input.prefix)
- ? file.path.slice(input.prefix.length)
- : file.path,
- })),
- key: input.key,
- mountPath: input.mountPath,
- targetPath: input.targetPath,
+ },
};
}
diff --git a/packages/eve/test/scenarios/sandbox-workspace-folders.scenario.test.ts b/packages/eve/test/scenarios/sandbox-workspace-folders.scenario.test.ts
index 6b9fa6b36..1193a711a 100644
--- a/packages/eve/test/scenarios/sandbox-workspace-folders.scenario.test.ts
+++ b/packages/eve/test/scenarios/sandbox-workspace-folders.scenario.test.ts
@@ -30,20 +30,18 @@ describe("sandbox workspace folder convention", () => {
// `materializeWorkspaceResources` → `prewarmSandboxes`; this test
// exercises the disk → sandbox round trip directly with the
// discovery output so it can stay focused on the local backend.
- const files = (
- await Promise.all(
- discovered.manifest.sandboxWorkspaces.map((workspace) =>
- materializeWorkspaceDirectory(workspace.sourcePath),
- ),
- )
- ).flat();
+ const trees = await Promise.all(
+ discovered.manifest.sandboxWorkspaces.map((workspace) =>
+ materializeWorkspaceDirectory(workspace.sourcePath),
+ ),
+ );
const appRoot = await createScratchDirectory("eve-sandbox-workspace-folders-");
const backend = createSandboxProviderHarness(createJustBashSandboxProvider(), undefined);
await backend.prepare({
appRoot,
- seedFiles: files.map((file) => ({ content: file.content, path: file.path })),
+ workspace: trees.flatMap((tree) => tree.workspace),
});
const handle = await backend.openSession({
@@ -75,7 +73,6 @@ describe("sandbox workspace folder convention", () => {
await backend.prepare({
appRoot,
- seedFiles: [],
});
const handle = await backend.openSession({
@@ -98,7 +95,7 @@ describe("sandbox workspace folder convention", () => {
it("materializes a fixture default workspace folder into a deterministic file list", async () => {
const fixtureApp = await scenarioApp(SANDBOX_WORKSPACES_DESCRIPTOR);
// Sanity check that the materializer reads the actual fixture from
- // disk and emits the expected logical paths under /workspace.
+ // disk and emits the expected workspace-relative paths.
const resolvedProject = await resolveDiscoveryProject(fixtureApp.appRoot);
const discovered = await discoverAgent(resolvedProject);
const [defaultWorkspace] = discovered.manifest.sandboxWorkspaces;
@@ -106,17 +103,18 @@ describe("sandbox workspace folder convention", () => {
throw new Error("expected the fixture to expose a default sandbox workspace");
}
- const files = await materializeWorkspaceDirectory(defaultWorkspace.sourcePath);
+ const { skills, workspace } = await materializeWorkspaceDirectory(defaultWorkspace.sourcePath);
- expect(files.map((file) => file.path).sort()).toEqual(["/workspace/notes.md"]);
+ expect(skills).toEqual([]);
+ expect(workspace.map((file) => file.relativePath)).toEqual(["notes.md"]);
- const notesFile = files.find((file) => file.path === "/workspace/notes.md");
+ const notesFile = workspace.find((file) => file.relativePath === "notes.md");
if (notesFile === undefined) {
- throw new Error("expected materialization to include /workspace/notes.md");
+ throw new Error("expected materialization to include notes.md");
}
// Cross-check the bytes by reading the source path directly.
const onDisk = await readFile(join(defaultWorkspace.sourcePath, "notes.md"), "utf8");
- expect(notesFile.content.toString("utf8")).toBe(onDisk);
+ expect(Buffer.from(notesFile.content).toString("utf8")).toBe(onDisk);
});
});