{"record":{"id":"943fded6a2129bae","repo":"vercel/ai","slug":"failed-to-create-sandbox-work-directory-workdir","errorCode":null,"errorMessage":"`Failed to create sandbox work directory ${workDir} (exit ${result.exitCode}): ${result.stderr || result.stdout}`","messagePattern":"`Failed to create sandbox work directory (.+?) \\(exit (.+?)\\): (.+?)`","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"packages/harness/src/agent/internal/sandbox-bootstrap.ts","lineNumber":200,"sourceCode":"  await onBootstrap({ session, workDir: bootstrapWorkDir, abortSignal });\n}\n\nexport async function ensureSandboxDirectory({\n  session,\n  workDir,\n  abortSignal,\n}: {\n  readonly session: SandboxSession;\n  readonly workDir: string;\n  readonly abortSignal?: AbortSignal;\n}): Promise<void> {\n  const result = await session.run({\n    command: 'mkdir -p \"$WORK_DIR\"',\n    env: { WORK_DIR: workDir },\n    abortSignal,\n  });\n  if (result.exitCode !== 0) {\n    throw new Error(\n      `Failed to create sandbox work directory ${workDir} (exit ${result.exitCode}): ${result.stderr || result.stdout}`,\n    );\n  }\n}\n\nasync function hashSandboxBootstrapIdentity({\n  recipeIdentity,\n  bootstrapHash,\n  workDir,\n}: {\n  readonly recipeIdentity?: string;\n  readonly bootstrapHash?: string;\n  readonly workDir?: string;\n}): Promise<string> {\n  const encoder = new TextEncoder();\n  const chunks: Uint8Array[] = [];\n  const pushString = (value: string) => {\n    chunks.push(encoder.encode(value));","sourceCodeStart":182,"sourceCodeEnd":218,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/harness/src/agent/internal/sandbox-bootstrap.ts#L182-L218","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Read the stderr in the message (e.g. 'Permission denied', 'Read-only file system') and fix the underlying sandbox filesystem issue.","Ensure workDir does not collide with an existing file and that the parent directory is writable by the sandbox user.","Rebuild or reconfigure the sandbox image/mount so the default working directory is writable."],"exampleFix":"// before (sandbox root mounted read-only)\nawait prepareSandboxForHarness({ sandboxConfig: { workDir: 'out' }, harnesses });\n// after (writable mount or different location)\nawait prepareSandboxForHarness({ sandboxConfig: { workDir: 'tmp/out' }, harnesses });","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"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; }","preventionTips":["Ensure the sandbox root filesystem/mount is writable","Verify the sandbox user has write permission on the default work dir","Avoid workDir names that collide with existing files","Monitor sandbox disk usage"],"tags":["sandbox","filesystem","shell","permissions"],"backgroundTag":"mkdir-failed","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}