vercel/ai · critical

`Failed to create sandbox work directory ${workDir} (exit ${

Error message

`Failed to create sandbox work directory ${workDir} (exit ${result.exitCode}): ${result.stderr || result.stdout}`

What it means

ensureSandboxDirectory runs 'mkdir -p "$WORK_DIR"' inside the sandbox session; if the command exits non-zero, the library throws with the exit code and the sandbox's stderr/stdout. This means the sandbox itself refused to create the directory — the message contains the sandbox's own diagnostic output.

Source

Thrown at packages/harness/src/agent/internal/sandbox-bootstrap.ts:200

  await onBootstrap({ session, workDir: bootstrapWorkDir, abortSignal });
}

export async function ensureSandboxDirectory({
  session,
  workDir,
  abortSignal,
}: {
  readonly session: SandboxSession;
  readonly workDir: string;
  readonly abortSignal?: AbortSignal;
}): Promise<void> {
  const result = await session.run({
    command: 'mkdir -p "$WORK_DIR"',
    env: { WORK_DIR: workDir },
    abortSignal,
  });
  if (result.exitCode !== 0) {
    throw new Error(
      `Failed to create sandbox work directory ${workDir} (exit ${result.exitCode}): ${result.stderr || result.stdout}`,
    );
  }
}

async function hashSandboxBootstrapIdentity({
  recipeIdentity,
  bootstrapHash,
  workDir,
}: {
  readonly recipeIdentity?: string;
  readonly bootstrapHash?: string;
  readonly workDir?: string;
}): Promise<string> {
  const encoder = new TextEncoder();
  const chunks: Uint8Array[] = [];
  const pushString = (value: string) => {
    chunks.push(encoder.encode(value));

View on GitHub (pinned to 69428b1f8b)

Solutions

  1. Read the stderr in the message (e.g. 'Permission denied', 'Read-only file system') and fix the underlying sandbox filesystem issue.
  2. Ensure workDir does not collide with an existing file and that the parent directory is writable by the sandbox user.
  3. Rebuild or reconfigure the sandbox image/mount so the default working directory is writable.

Example fix

// before (sandbox root mounted read-only)
await prepareSandboxForHarness({ sandboxConfig: { workDir: 'out' }, harnesses });
// after (writable mount or different location)
await prepareSandboxForHarness({ sandboxConfig: { workDir: 'tmp/out' }, harnesses });
Defensive patterns

Strategy: try-catch

Try / catch

try { await prepareSandboxForHarness({ sandboxConfig, harnesses }); } catch (e) { const m = /exit (\d+)\): (.*)/.exec(e.message); if (m) { console.error('mkdir failed:', m[2]); /* fix fs perms or abort */ } else throw e; }

Prevention

When it happens

Trigger: Running a sandboxed bootstrap where mkdir -p fails: read-only filesystem, permission denied for the sandbox user, invalid path components surviving normalization, or full disk.

Common situations: Mounting the sandbox root read-only; workDir colliding with a file of the same name; sandbox image with restricted permissions; NFS/volume mount permission issues.

Related errors


AI-assisted analysis of vercel/ai@69428b1f8b (2026-08-30). Data as JSON: /api/errors/943fded6a2129bae. Report an issue: GitHub.