vercel/ai · error · Error
Failed to resolve sandbox default working directory (exit ${
Error message
Failed to resolve sandbox default working directory (exit ${result.exitCode}): ${result.stderr || result.stdout} What it means
Thrown by resolveSandboxDefaultWorkingDirectory in packages/harness/src/utils/resolve-sandbox-default-working-directory.ts when the `pwd` command executed inside the sandbox session exits non-zero. The harness needs the sandbox's default working directory before running commands, and this failure means the sandbox shell could not even report its cwd. The stderr/stdout of the failed command is embedded in the message to help diagnose the sandbox-side problem.
Source
Thrown at packages/harness/src/utils/resolve-sandbox-default-working-directory.ts:21
import type { HarnessV1NetworkSandboxSession } from '../v1';
export async function resolveSandboxDefaultWorkingDirectory({
sandboxSession,
abortSignal,
}: {
readonly sandboxSession: HarnessV1NetworkSandboxSession | SandboxSession;
readonly abortSignal?: AbortSignal;
}): Promise<string> {
if ('defaultWorkingDirectory' in sandboxSession) {
return sandboxSession.defaultWorkingDirectory;
}
const result = await sandboxSession.run({
command: 'pwd',
abortSignal,
});
if (result.exitCode !== 0) {
throw new Error(
`Failed to resolve sandbox default working directory (exit ${result.exitCode}): ${result.stderr || result.stdout}`,
);
}
const cwd = result.stdout.trim();
if (!posix.isAbsolute(cwd)) {
throw new Error(
`Failed to resolve sandbox default working directory: expected an absolute path, got ${JSON.stringify(cwd)}.`,
);
}
return cwd === '/' ? cwd : cwd.replace(/\/+$/, '');
}
View on GitHub (pinned to 69428b1f8b)
Solutions
- Inspect the stderr/stdout embedded in the error to see why `pwd` failed inside the sandbox.
- Verify the sandbox image/VM is healthy and has a POSIX shell with `pwd` available.
- Implement `defaultWorkingDirectory` on your sandbox session so the harness can skip the `pwd` probe entirely.
- Check that the sandbox session is running/not aborted before calling harness setup.
Example fix
// before
const session = createCustomSandbox({ image: 'scratch' }); // no shell
const cwd = await resolveSandboxDefaultWorkingDirectory({ sandboxSession: session });
// after
const session = createCustomSandbox({ image: 'debian:slim', defaultWorkingDirectory: '/workspace' });
const cwd = await resolveSandboxDefaultWorkingDirectory({ sandboxSession: session }); Defensive patterns
Strategy: try-catch
Validate before calling
// Pre-check: does the sandbox expose a working directory?
if (!('defaultWorkingDirectory' in sandboxSession)) {
const probe = await sandboxSession.run({ command: 'command -v pwd && pwd' });
if (probe.exitCode !== 0) throw new Error('Sandbox cannot run pwd: ' + probe.stderr);
} Type guard
function hasDefaultWorkingDirectory(s: object): s is { defaultWorkingDirectory: string } {
return 'defaultWorkingDirectory' in s && typeof (s as any).defaultWorkingDirectory === 'string';
} Try / catch
try {
const cwd = await resolveSandboxDefaultWorkingDirectory({ sandboxSession });
} catch (error) {
// message includes exit code + stderr; inspect, then fail fast or recreate sandbox
throw new Error(`Sandbox unusable, recreate the session: ${(error as Error).message}`);
} Prevention
- Provide `defaultWorkingDirectory` on your sandbox session to skip the pwd probe.
- Use a sandbox image with a POSIX shell and coreutils.
- Verify the session is running before harness setup.
- Smoke-test the sandbox with a trivial `run({ command: 'true' })` first.
When it happens
Trigger: Calling prepareSandboxForHarness (or any code path reaching resolveSandboxDefaultWorkingDirectory) with a sandbox session that does not expose a `defaultWorkingDirectory` property, where `sandboxSession.run({ command: 'pwd' })` returns exitCode !== 0 — e.g. the sandbox shell fails to start, `pwd` is unavailable in a minimal image, or the session is already terminated.
Common situations: Custom sandbox implementations whose `run` fails on shell startup (bad image, missing shell); sandboxes where the working directory was deleted; sessions aborted mid-run; minimal containers lacking coreutils.
Related errors
- 'HarnessAgent: `sandboxConfig.onBootstrap` and `sandboxConfi
- `Failed to create sandbox work directory ${workDir} (exit ${
- Failed to resolve sandbox default working directory: expecte
- Unable to resolve sandbox HOME directory: ${result.stderr ||
- Invalid AI SDK harness skills manifest: ${manifestPath}
AI-assisted analysis of vercel/ai@69428b1f8b (2026-08-30).
Data as JSON: /api/errors/5349a2655435a92c.
Report an issue: GitHub.