Quick Example
Core Options
Console
Without a
consoleHandler, console is allowed only at PERMISSIVE and writes to the host process console. With one, scripts may use console at every security level and each call reaches the handler instead:
levelis'log' | 'info' | 'warn' | 'error' | 'debug'(ConsoleLevel);messageis the formatted line: arguments joined by spaces, objects JSON-serialized.maxConsoleCallsandmaxConsoleOutputBytesare checked before the handler runs. Past a limit, the script’s call throws and the handler is not called.- The handler’s return value is ignored, and anything it throws or rejects with is swallowed: the script sees neither.
- The script’s
consoleis a frozen, null-prototype object built inside the sandbox. It holds no reference the script can reach to the handler or to any host object. - Supported by the double VM (default), the
vmadapter and theworker_threadsadapter. A custom sandbox adapter receives the handler ascontext.consoleHandler; the built-inInterpreterAdapterhas noconsole, so a script that uses it fails there ('__safe_console' is not defined).@enclave-vm/browserhas its own options and is unchanged. - A
consoleHandlercannot be combined with aconsoleentry inglobals(the constructor throws aTypeError).
Memory Tracking
Reference Sidecar
Double VM Layer
AI Scoring Gate
Worker Pool Adapter
Custom Sandbox Adapter
@enclave-vm/core runs scripts with node:vm. Where that is not available (a browser worker, an edge runtime), run() fails with @enclave-vm/core needs node:vm, ...; pass a sandboxAdapter to run scripts another way. It replaces the double VM and the adapter option.
execute, but isolation is then the adapter’s job: it receives the ExecutionContext (limits, tool handler, stats, abort signal) and must enforce it. The caller owns the adapter: enclave.dispose() does not dispose it, so one adapter can serve several enclaves. In a browser, @enclave-vm/browser is usually the better fit.
Security Options
Execution Result
Therun() method returns:
Error Codes
Related
- Overview - Getting started
- Security Levels - Preset comparison
- Tool System - Tool integration