Create a new SandboxedToolForge instance.
Optional config: SandboxedToolForgeConfigOptional configuration overrides. All fields have sensible defaults (128 MB memory, 5000 ms timeout, no domain restrictions).
Static analysis of code — reject dangerous patterns before execution.
Scans the source string for banned API usage patterns using regex matching. If an API is not present in the allowlist, references to it are also flagged.
Checked patterns (always banned):
eval(), new Function(), require(), import, process.*child_process, fs.write*, fs.unlink, fs.rm, fs.rmdirConditionally banned (when not in allowlist):
fetch( — when 'fetch' is not in the allowlistfs.* — when 'fs.readFile' is not in the allowlistcrypto.* — when 'crypto' is not in the allowlistThe raw source code string to validate.
The set of APIs the code is permitted to use.
An object with valid: true if no violations were found, or
valid: false with a violations array describing each flagged pattern.
const forge = new SandboxedToolForge();
const result = forge.validateCode('eval("exploit")', []);
// result.valid === false
// result.violations === ['eval() is forbidden']
Execute agent-generated code in the sandbox.
The code must define a function named execute that accepts a single
argument and returns the output:
function execute(input) { return input.a + input.b; }
Execution flow:
validateCode() — reject immediately if violations are found.execute.vm sandbox with a restricted global context.The execution request containing code, input, allowlist, and resource limits.
A SandboxExecutionResult with the output (on success) or error description (on failure), plus execution time telemetry.
const result = await forge.execute({
code: 'function execute(input) { return { sum: input.a + input.b }; }',
input: { a: 10, b: 20 },
allowlist: [],
memoryMB: 128,
timeoutMs: 5000,
});
// result.success === true
// result.output === { sum: 30 }
Runs agent-generated code in an isolated sandbox with strict resource limits.
Attempts to use
isolated-vmfor true V8 isolate sandboxing. Falls back to Node.jsvmmodule with timeout ifisolated-vmis not installed.Resource limits:
Allowlisted APIs (each requires explicit opt-in):
fetch: HTTP requests (domain-restricted)fs.readFile: Read-only file access (path-restricted, max 1 MB)crypto: Hashing and HMAC onlyExample