Create a new SandboxedToolForge instance.
Optional config: SandboxedToolForgeConfigOptional configuration overrides. All fields have sensible defaults (128 MB memory, 5000 ms timeout, no domain restrictions).
The options this forge runs with, defaults applied. The engine reads them to check a host-built forge against a ceiling.
Under a ceiling the engine attaches its broker: from then on the functions injected into forged code are the broker's, and every execution needs a call handle. A forge serves one broker.
Error when a different broker is already attached.
Static analysis of code — reject dangerous patterns before execution.
Scans the source string for banned API usage patterns using regex
matching. The list is read in catalogue names first (fs.readFile
stands for fs.read, fs.writeFile for fs.write, fs.unlink for
fs.delete).
Checked patterns (always banned):
eval(), new Function(), require(), import, process.*child_process; every fs.write* name but fs.writeFile, every
fs.unlink* name but fs.unlink; fs.rm, fs.rmdir,
fs.appendFile, fs.truncateConditionally banned (when the list does not grant them):
fetch( — without fetchfs.writeFile — without fs.write; fs.unlink — without fs.deletefs. reference — without fs.read (or its alias fs.readFile)crypto.* — without cryptoThe raw source code string to validate.
The capabilities the code may use, in either name.
valid: true with no violations, 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.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 }
Readonly executorWhat runs forged code: the in-process executor unless the host passed one.
Validates agent-generated code and runs it on an executor, by default in an in-process node:vm context (InProcessExecutor).
node:vmis not a security mechanism (Node's documentation): the checks here hold for code that acts through the injected functions, and memory is reported, not limited.Runtime bounds:
Allowlisted APIs (each requires explicit opt-in):
fetch: HTTP requests (the first URL's host is checked whenfetchDomainAllowlistis set)fs.readFile: Read-only file access (path-restricted, max 1 MB)crypto: Hashing and HMAC onlyExample