{"record":{"id":"418bcad6baf44d69","repo":"vercel/ai","slug":"failed-to-resolve-sandbox-default-working-director-418bca","errorCode":null,"errorMessage":"Failed to resolve sandbox default working directory: expected an absolute path, got ${JSON.stringify(cwd)}.","messagePattern":"Failed to resolve sandbox default working directory: expected an absolute path, got (.+?)\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/harness/src/utils/resolve-sandbox-default-working-directory.ts","lineNumber":28,"sourceCode":"  readonly abortSignal?: AbortSignal;\n}): Promise<string> {\n  if ('defaultWorkingDirectory' in sandboxSession) {\n    return sandboxSession.defaultWorkingDirectory;\n  }\n\n  const result = await sandboxSession.run({\n    command: 'pwd',\n    abortSignal,\n  });\n  if (result.exitCode !== 0) {\n    throw new Error(\n      `Failed to resolve sandbox default working directory (exit ${result.exitCode}): ${result.stderr || result.stdout}`,\n    );\n  }\n\n  const cwd = result.stdout.trim();\n  if (!posix.isAbsolute(cwd)) {\n    throw new Error(\n      `Failed to resolve sandbox default working directory: expected an absolute path, got ${JSON.stringify(cwd)}.`,\n    );\n  }\n  return cwd === '/' ? cwd : cwd.replace(/\\/+$/, '');\n}\n","sourceCodeStart":10,"sourceCodeEnd":34,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/harness/src/utils/resolve-sandbox-default-working-directory.ts#L10-L34","documentation":"Thrown by resolveSandboxDefaultWorkingDirectory when `pwd` succeeds but its output is not a POSIX absolute path. The harness requires an absolute working directory to resolve relative paths for sandbox commands; a relative or empty cwd indicates a broken or non-standard sandbox environment. The JSON-stringified cwd is included to reveal whitespace or unexpected output.","triggerScenarios":"`sandboxSession.run({ command: 'pwd' })` returns exitCode 0 but `result.stdout.trim()` is empty, relative (e.g. `home/user`), a Windows-style path, or polluted with extra output (e.g. a shell printing a banner before `pwd`).","commonSituations":"Custom sandbox `run` implementations that mix command output with log/banner text; sandboxes on non-POSIX filesystems; misconfigured shell profiles echoing to stdout; Windows-based sandbox runtimes.","solutions":["Fix the sandbox environment so `pwd` prints only a POSIX absolute path (remove profile scripts echoing to stdout).","Implement `defaultWorkingDirectory` on the sandbox session to bypass the `pwd` probe.","Use a Linux/POSIX sandbox image so cwd is an absolute POSIX path.","Check `pwd` output manually inside the sandbox to see what is actually returned."],"exampleFix":"// before\n// ~/.bashrc prints: echo \"Welcome to sandbox\"\nconst cwd = await resolveSandboxDefaultWorkingDirectory({ sandboxSession }); // 'expected an absolute path, got \"Welcome to sandbox\"'\n// after\n// remove echo from ~/.bashrc, or:\nconst session = { ...sandboxSession, defaultWorkingDirectory: '/root' };","handlingStrategy":"validation","validationCode":"const probe = await sandboxSession.run({ command: 'pwd' });\nconst cwd = probe.stdout.trim();\nif (probe.exitCode !== 0 || !require('node:path').posix.isAbsolute(cwd)) {\n  throw new Error(`Sandbox pwd output is not absolute: ${JSON.stringify(cwd)}`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  const cwd = await resolveSandboxDefaultWorkingDirectory({ sandboxSession });\n} catch (error) {\n  if (/expected an absolute path/.test((error as Error).message)) {\n    // fall back to a known-good directory\n    return '/root';\n  }\n  throw error;\n}","preventionTips":["Remove shell profile scripts that echo to stdout in the sandbox image.","Prefer POSIX (Linux) sandboxes over Windows runtimes.","Set `defaultWorkingDirectory` explicitly on the session.","Test `pwd` output inside the sandbox before integration."],"tags":["sandbox","path","harness","validation"],"backgroundTag":"invalid-absolute-path","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}