JuliusBrussee/caveman · error
cave_sandbox_source_read_root_refused
cave_sandbox_source_read_root_refused
Error message
cave_sandbox_source_read_root_refused
What it means
When computing the common ancestor directory of the sandbox source files, the walk up the directory tree hit the filesystem root without finding an ancestor that contains all paths. The library refuses to grant `--allow-fs-read` on `/` (or a drive root) because that would give the sandboxed worker read access to the entire filesystem. It is a deliberate fail-closed security refusal.
Solutions
- Stage all source files under one dedicated subdirectory (e.g. `<project>/.cave-stage/`) so the common ancestor is a real project path, not `/`
- Check for symlinks or path spellings that resolve outside the intended staging tree and normalize them
- Reduce the source set (or split into separate workers) so it fits under the 1024-file per-path flag threshold, avoiding ancestor consolidation entirely
Example fix
// before sandboxSourceReadFlags(["/etc/a.ts", "/home/u/b.ts"], "/stage") // after sandboxSourceReadFlags(["/stage/etc/a.ts", "/stage/home/u/b.ts"], "/stage/src")
Defensive patterns
Strategy: validation
Validate before calling
const resolved = files.map((f) => resolve(dirname(f)));
if (resolved.some((d) => dirname(d) === d || d === '/')) throw new Error('source paths must live under a staging subdirectory, not the filesystem root'); Try / catch
try { const flags = sandboxSourceReadFlags(files, stagingRoot); } catch (e) { if (String((e as Error).message).includes('cave_sandbox_source_read_root_refused')) { /* restage under one subdir */ } else throw e; } Prevention
- Stage every source file under one dedicated non-root directory
- Resolve symlinks before collecting source paths
- Keep source paths on one volume/drive so a common ancestor exists below the root
When it happens
Trigger: Calling `sandboxSourceReadFlags` with more than 1024 files whose common ancestor is the root directory — e.g. files spread across `/etc/foo.ts` and `/home/x/bar.ts`, or staged files placed directly under `/`. Also thrown when the while loop climbs to the root (`dirname(ancestor) === ancestor`) inside `commonAncestorDir`.
Common situations: A staging root created at `/` or `/tmp` on systems where resolved paths diverge across devices/mounts, source files spread across multiple top-level directories (e.g. different drive letters on Windows), or symlinks resolving outside the project so the shared ancestor collapses to `/`.
Understand the failure class
Background: Path traversal blocked: "path escapes the workspace" and "outside site root" errors when a path will not stay inside its allowed directory — this error's family across 26 libraries.
Related errors
- cave_tool_sandbox_entry_escapes_root
- cave_host_sandbox_nested_under_required
- cave_live_eval_sandbox_profile_escapes_root
- cave_sandbox_child_process_containment_unavailable
- cave_sandbox_conformance_failed
AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20).
Data as JSON: /api/errors/847c94030e377d81.
Report an issue: GitHub.
Appendix: source
Thrown at packages/agent/src/runtime.ts:4893
* files to their common ancestor directory. A large project would
* otherwise blow the OS argument limit (E2BIG) and the tool could not spawn at
* all. The collapse is safe here: `sourceFiles` are paths inside the per-run
* STAGED COPY, which already contains only the reachable source graph — never
* the real project root with its .env and credentials.
*/
const SANDBOX_FS_READ_FLAG_THRESHOLD = 1024;
function commonAncestorDir(paths: readonly string[]): string {
const dirs = paths.map((path) => resolve(dirname(path)));
const first = dirs[0];
if (first === undefined) {
throw new Error("cave_sandbox_source_staging_root_required");
}
let ancestor = first;
while (dirs.some((path) => escapesRoot(relative(ancestor, path)))) {
const parent = dirname(ancestor);
if (parent === ancestor) {
throw new Error("cave_sandbox_source_read_root_refused");
}
ancestor = parent;
}
if (dirname(ancestor) === ancestor) {
throw new Error("cave_sandbox_source_read_root_refused");
}
return ancestor;
}
export function sandboxSourceReadFlags(
sourceFiles: readonly string[],
stagingRoot?: string,
): string[] {
if (sourceFiles.length <= SANDBOX_FS_READ_FLAG_THRESHOLD) {
return sourceFiles.map((path) => `--allow-fs-read=${path}`);
}
if (stagingRoot === undefined) {
throw new Error("cave_sandbox_source_staging_root_required");View on GitHub (pinned to 3ee70a1026)