{"record":{"id":"5d49fafefc13ebfb","repo":"vercel/ai","slug":"harnessagent-sandboxconfig-workdir-must-be-rel","errorCode":null,"errorMessage":"'HarnessAgent: `sandboxConfig.workDir` must be relative.'","messagePattern":"'HarnessAgent: `sandboxConfig\\.workDir` must be relative\\.'","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/harness/src/agent/internal/sandbox-bootstrap.ts","lineNumber":52,"sourceCode":"  }\n}\n\nexport function normalizeSandboxWorkDir(workDir: string): string {\n  if (workDir.length === 0) {\n    throw new Error('HarnessAgent: `sandboxConfig.workDir` must not be empty.');\n  }\n  if (workDir.includes('\\0')) {\n    throw new Error(\n      'HarnessAgent: `sandboxConfig.workDir` must not contain NUL.',\n    );\n  }\n  if (workDir.includes('\\\\')) {\n    throw new Error(\n      'HarnessAgent: `sandboxConfig.workDir` must use POSIX path separators.',\n    );\n  }\n  if (posix.isAbsolute(workDir)) {\n    throw new Error('HarnessAgent: `sandboxConfig.workDir` must be relative.');\n  }\n\n  const normalized = posix.normalize(workDir);\n  if (\n    normalized === '.' ||\n    normalized === '..' ||\n    normalized.startsWith('../')\n  ) {\n    throw new Error(\n      'HarnessAgent: `sandboxConfig.workDir` must stay inside the sandbox default working directory.',\n    );\n  }\n  return normalized;\n}\n\nexport function resolveSessionWorkDir({\n  defaultWorkingDirectory,\n  harnessId,","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/harness/src/agent/internal/sandbox-bootstrap.ts#L34-L70","documentation":"The sandbox work directory must be a path relative to the sandbox's default working directory. Absolute paths (posix.isAbsolute) are rejected because the library resolves workDir against the sandbox's internal root, and absolute input could point outside the sandbox root it controls.","triggerScenarios":"Passing an absolute POSIX path like '/tmp/work' or '/home/user/project' as sandboxConfig.workDir to prepareSandboxForHarness or agent creation.","commonSituations":"Reusing a host filesystem path as the sandbox workDir; misreading the docs and thinking workDir is an absolute container path.","solutions":["Remove the leading slash and pass a relative path, e.g. 'workspace/runs' instead of '/workspace/runs'.","If you have an absolute host path, extract the relevant relative portion (path.posix.relative(root, absPath)).","Check config files for values that accidentally start with '/'."],"exampleFix":"// before\nawait prepareSandboxForHarness({ sandboxConfig: { workDir: '/tmp/agent-work' }, harnesses: [...] });\n// after\nawait prepareSandboxForHarness({ sandboxConfig: { workDir: 'agent-work' }, harnesses: [...] });","handlingStrategy":"validation","validationCode":"if (path.posix.isAbsolute(workDir)) throw new Error('workDir must be relative');","typeGuard":"function isRelativePosixPath(v: unknown): v is string { return typeof v === 'string' && v.length > 0 && !path.posix.isAbsolute(v); }","tryCatchPattern":"try { await prepareSandboxForHarness({ sandboxConfig: { workDir }, harnesses }); } catch (e) { if (e.message.includes('must be relative')) { workDir = workDir.replace(/^\\//, ''); } else throw e; }","preventionTips":["Document that workDir is relative to the sandbox default working directory","Strip leading slashes when accepting paths from users","Write a small config validator for sandbox settings"],"tags":["path","validation","sandbox","configuration"],"backgroundTag":"absolute-path-not-allowed","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}