Skip to content

Commit 62dbb75

Browse files
committed
fix(sandbox): ensure skills directories exist before sandbox container spawn (fixes #94425)
1 parent 2e44610 commit 62dbb75

2 files changed

Lines changed: 41 additions & 1 deletion

File tree

‎src/agents/sandbox/workspace-mounts.test.ts‎

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ import fs from "node:fs";
44
import os from "node:os";
55
import path from "node:path";
66
import { afterEach, describe, expect, it } from "vitest";
7-
import { appendWorkspaceMountArgs } from "./workspace-mounts.js";
7+
import {
8+
appendWorkspaceMountArgs,
9+
resolveReadOnlyWorkspaceSkillMounts,
10+
} from "./workspace-mounts.js";
11+
import { ensureSandboxWorkspace } from "./workspace.js";
812

913
const tmpDirs: string[] = [];
1014

@@ -249,4 +253,33 @@ describe("appendWorkspaceMountArgs", () => {
249253
`${path.join(sandboxWorkspaceDir, "skills")}:/workspace/skills:ro,z`,
250254
);
251255
});
256+
257+
it("creates skills directories so read-only overlays are always resolved", async () => {
258+
// When a new sandbox workspace is created without pre-existing skills
259+
// directories, ensureSandboxWorkspace must create them so that
260+
// resolveReadOnlyWorkspaceSkillMounts finds existing sources.
261+
const agentWorkspaceDir = makeTempWorkspace();
262+
263+
await ensureSandboxWorkspace(agentWorkspaceDir, undefined, true);
264+
265+
// Directories must exist after workspace setup.
266+
const skillsDir = path.join(agentWorkspaceDir, "skills");
267+
const agentsSkillsDir = path.join(agentWorkspaceDir, ".agents", "skills");
268+
expect(fs.existsSync(skillsDir)).toBe(true);
269+
expect(fs.existsSync(agentsSkillsDir)).toBe(true);
270+
271+
// Mount resolution must find them and include the read-only overlays.
272+
const mounts = resolveReadOnlyWorkspaceSkillMounts({
273+
workspaceDir: agentWorkspaceDir,
274+
agentWorkspaceDir,
275+
workdir: "/workspace",
276+
workspaceAccess: "rw",
277+
});
278+
expect(mounts).toEqual(
279+
expect.arrayContaining([
280+
expect.objectContaining({ containerPath: "/workspace/skills" }),
281+
expect.objectContaining({ containerPath: "/workspace/.agents/skills" }),
282+
]),
283+
);
284+
});
252285
});

‎src/agents/sandbox/workspace.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,11 @@ export async function ensureSandboxWorkspace(
7070
ensureBootstrapFiles: !skipBootstrap,
7171
skipOptionalBootstrapFiles,
7272
});
73+
74+
// Ensure skills directories exist on the host so the read-only mount overlay is
75+
// always applied. Without this, resolveReadOnlyWorkspaceSkillMounts silently skips
76+
// the mount when the host directory is missing, leaving skills paths writable in the
77+
// sandbox (reported as #94425).
78+
await fs.mkdir(path.join(workspaceDir, "skills"), { recursive: true });
79+
await fs.mkdir(path.join(workspaceDir, ".agents", "skills"), { recursive: true });
7380
}

0 commit comments

Comments
 (0)