JuliusBrussee/caveman · error

cave_sandbox_tool_failed

cave_sandbox_tool_failed

Error message

cave_sandbox_tool_failed

What it means

Sandboxed tool execution returns a result envelope; if the execution reports not-ok without a more specific code, the runtime throws cave_sandbox_tool_failed as the generic failure signal. It means the tool itself (or its sandbox harness) failed inside the temporary workspace — the workspace is then always cleaned up in the finally block.

Solutions

  1. Inspect the tool's own logs/output to find the underlying crash cause, since this generic code carries no detail.
  2. Fix the tool so it exits with a structured error code (result.code) for its failure modes.
  3. Retry the tool invocation if the cause was transient (OOM/timeout), possibly with smaller inputs.
  4. Verify tool params and allowSideEffects/allowNetwork settings match what the tool expects before re-running.

Example fix

// before: tool crashes with bare exit
toolMain();
// after: emit a structured code the sandbox can surface
try {
  await toolMain();
} catch (e) {
  process.exitCode = 1;
  emitSandboxCode('cave_tool_invalid_params', String(e));
}
Defensive patterns

Strategy: try-catch

Validate before calling

if (!toolCommandHealthy(tool)) throw new Error('tool binary fails smoke test; fix before sandboxing');

Type guard

const sandboxResultOk = (r) => r !== undefined && r.ok === true && r.value !== undefined;

Try / catch

try {
  return await runSandboxedTool(tool, params);
} catch (e) {
  if (e.message === 'cave_sandbox_tool_failed') {
    logToolCrash(tool.name, params);
    return null; // or retry with backoff
  }
  throw e;
}

Prevention

When it happens

Trigger: The sandbox result envelope has ok === false and result.code is undefined/empty when running a tool via the sandbox runner (runtime.ts:4866) — e.g. the tool process crashed without setting an error code, or the harness failed before assigning a specific code.

Common situations: Tool binary/script crashing (segfault, unhandled exception) without emitting a structured error code; timeout or OOM kill inside the sandbox leaving no code; harness-level failure (workspace staging issue) before the tool's own error mapping ran.

Understand the failure class

Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.

Related errors


AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20). Data as JSON: /api/errors/8c582e4f9cdffcf7. Report an issue: GitHub.

Appendix: source

Thrown at packages/agent/src/runtime.ts:4866

          reject(new Error(`cave_sandbox_failed:${redactSandboxError(Buffer.concat(stderr).toString("utf8"))}`));
          return;
        }
        reject(new Error("cave_sandbox_invalid_output"));
      });
      combined.addEventListener("abort", onAbort, { once: true });
      if (combined.aborted) onAbort();
      child.stdin.end(JSON.stringify({
        entry: pathToFileURL(entryPath).href,
        agentPath: executionContext.agentPath,
        rootDefinitionSha256: executionContext.rootDefinitionSha256,
        toolDefinitionSha256,
        tool: toolName,
        params,
        allowSideEffects,
        allowNetwork: profile?.network === true,
      }));
    });
    if (!result.ok) throw new Error(result.code ?? "cave_sandbox_tool_failed");
    return result.value;
  } finally {
    await rm(workspace, { recursive: true, force: true });
  }
}

/**
 * Above this many per-file `--allow-fs-read` flags, collapse the staged source
 * 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)));

View on GitHub (pinned to 3ee70a1026)