vercel/ai · error
Pi private session directory ${JSON.stringify(privateSession
Error message
Pi private session directory ${JSON.stringify(privateSessionDir)} must be outside sessionWorkDir ${JSON.stringify(input.sessionWorkDir)}. What it means
The adapter computes a private directory under the sandbox HOME where Pi session files are stored, and verifies that it does not live inside the agent's session work directory (so session state never leaks into the agent workspace). It throws when the private dir resolves to, or inside, sessionWorkDir. This is a configuration-invariant failure of resolvePiPrivateSessionDirectory.
Source
Thrown at packages/harness-pi/src/pi-resume-state.ts:56
readonly sessionWorkDir: string;
readonly sessionId: string;
}): string {
const sessionKey = createHash('sha256').update(input.sessionId).digest('hex');
const privateSessionDir = path.posix.join(
input.sandboxHomeDir,
'.ai-sdk',
'harness-pi',
sessionKey,
);
const relativePath = path.posix.relative(
input.sessionWorkDir,
privateSessionDir,
);
if (
relativePath === '' ||
(!relativePath.startsWith('../') && !path.posix.isAbsolute(relativePath))
) {
throw new Error(
`Pi private session directory ${JSON.stringify(privateSessionDir)} must be outside sessionWorkDir ${JSON.stringify(input.sessionWorkDir)}.`,
);
}
return privateSessionDir;
}
function resolveContainedHostPath(input: {
readonly baseDir: string;
readonly sessionFileName: string;
}): string {
const baseDir = path.resolve(input.baseDir);
const filePath = path.resolve(
baseDir,
safePiSessionFileName(input.sessionFileName),
);
const relativePath = path.relative(baseDir, filePath);
if (
relativePath === '' ||View on GitHub (pinned to 69428b1f8b)
Solutions
- Move sessionWorkDir to a dedicated agent workspace directory that is not inside sandboxHomeDir
- Ensure sandboxHomeDir is not a parent (or equal) of sessionWorkDir
- If using defaults, do not override sessionWorkDir to point under the home directory
Example fix
// before
resolvePiPrivateSessionDirectory({
sandboxHomeDir: '/home/agent',
sessionWorkDir: '/home/agent', // collides: private dir is inside work dir
sessionId,
});
// after
resolvePiPrivateSessionDirectory({
sandboxHomeDir: '/home/agent',
sessionWorkDir: '/home/agent/workspace', // outside the state path
sessionId,
}); Defensive patterns
Strategy: validation
Validate before calling
import path from 'node:path';
export function assertWorkDirOutsideHome(sandboxHomeDir: string, sessionWorkDir: string): void {
const rel = path.posix.relative(sessionWorkDir, path.posix.join(sandboxHomeDir, '.ai-sdk'));
if (rel === '' || (!rel.startsWith('../') && !path.posix.isAbsolute(rel))) {
throw new Error('sessionWorkDir must not overlap the sandbox home .ai-sdk directory');
}
} Prevention
- Keep the agent workspace and sandbox HOME in disjoint directory trees
- Never set sessionWorkDir to the home dir or any ancestor of <home>/.ai-sdk
- Add the containment assertion to config loading so failures surface at startup
When it happens
Trigger: Calling resolvePiPrivateSessionDirectory (directly or via resume lifecycle code) with a sandboxHomeDir laid out such that `<sandboxHomeDir>/.ai-sdk/harness-pi/<hash>` equals or is nested within the given sessionWorkDir — e.g. sessionWorkDir set to the sandbox home itself, to `<home>/.ai-sdk`, or to `<home>/.ai-sdk/harness-pi`.
Common situations: Misconfiguring the sandbox so the agent workspace and sandbox HOME point at the same directory, or intentionally pointing sessionWorkDir at the home dir to 'simplify' pathing; also occurs when a custom sessionWorkDir overlaps the .ai-sdk state folder.
Related errors
- Invalid argument for parameter model: model ${model.provider
- The Claude Code harness cannot use `mintBridgeToken` with a
- The Claude Code harness requires an explicit `port` when usi
- The Claude Code harness requires an explicit `portEndpoint`
- Cline private session directory ${JSON.stringify(privateSess
AI-assisted analysis of vercel/ai@69428b1f8b (2026-08-30).
Data as JSON: /api/errors/32b640027e1da0cf.
Report an issue: GitHub.