/** * Polyglot code executor — run snippets of Python, Node, TypeScript, or Bash * inside a `SandboxPolicy`. The runner is the missing primitive that turns * the harness into a "Claude Code" style agent loop: rather than ask the * model to author whole files for every task, hand it a small `run_code` * tool and let it batch primitive operations in its native language. * * Design goals * ------------ * - **Polyglot**: TS harness can launch `python3 -c …` or `node -e …` * without the agent author having to know which interpreter is on $PATH. * Auto-detect each language once on first use. * - **Sandboxed**: every spawn inherits the workspace cwd from * `SandboxPolicy.workspace`, refuses to start when `allowShell === false`, * and caps stdout/stderr at `sandbox.maxOutputBytes`. * - **Stateless**: no persistent REPL state between calls (this is *not* * Jupyter). For session-scoped state the agent should write to a file. * Stateless executors are easier to reason about and trivial to * parallelize across forks. * - **Tool-shaped**: `executor.tools()` returns one LLM-callable * `run_code({ language, source })` tool plus a thin `which_languages()` * capability probe so the model can branch on what's installed. * * Why this is the right shape * --------------------------- * Claude Code conflates "shell" and "code execution" inside its single * `BashTool`. That works for an interactive engineer running mostly bash, * but it forces every Python snippet through `python3 -c "$(cat <>; /** Default per-call wall clock in milliseconds. */ defaultTimeoutMs?: number; /** Languages that should NOT be exposed even if their interpreter exists. */ disable?: CodeLanguage[]; /** Optional streaming sink for live stdout. */ onOutput?: (chunk: string) => void; } export interface CodeRunResult { language: CodeLanguage; stdout: string; stderr: string; exitCode: number; truncated: boolean; durationMs: number; } /** * Polyglot code runner. Holds a `SandboxPolicy` reference and an * interpreter table; calling `.run(...)` shells out to the right binary. */ export declare class CodeExecutor { readonly sandbox: SandboxPolicy; readonly defaultTimeoutMs: number; private readonly interpreters; private readonly disabled; private readonly onOutput?; private detectedCache?; constructor(sandbox: SandboxPolicy, opts?: CodeExecutorOptions); /** Run `source` under the chosen language; returns captured streams. */ run(language: CodeLanguage, source: string, opts?: { timeoutMs?: number; stdin?: string; }): Promise; /** Probe interpreters once and cache. Used by `which_languages` tool. */ detect(): Promise>; /** Build LLM-callable tools that wrap this executor. */ tools(): HarnessTool[]; private materialize; } //# sourceMappingURL=code-executor.d.ts.map