Skip to content

feat(core): accept a host-supplied sandboxAdapter - #96

Merged
frontegg-david merged 1 commit into
fix/browser-timeout-tool-callsfrom
feat/core-sandbox-adapter-option
Oct 4, 2026
Merged

frontegg-david merged 1 commit into
fix/browser-timeout-tool-callsfrom
feat/core-sandbox-adapter-option

Conversation

@frontegg-david

@frontegg-david frontegg-david commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Stack 5/10: main ← #92 ← #93 ← #94 ← #95 ← this ← #98 ← #99 ← #100 ← #101 ← #102

Fixes #91.

Validation

All three points reproduce:

  1. With vm mapped to an empty module, run() fails with TypeError: vm.createContext is not a function (DOUBLE_VM_EXECUTION_ERROR).
  2. getAdapter() returns the double VM before it reads config.adapter. So { adapter: 'isolated-vm' } runs fine, and the documented { adapter: 'worker_threads', workerPoolConfig } example actually runs in the double VM.
  3. InterpreterAdapter is exported, but new Enclave({ adapter: 'interpreter', doubleVm: { enabled: false } }) fails with Unknown adapter: interpreter.

Fix

New sandboxAdapter option. It takes any object with execute(code, context) and dispose(), and runs the script in place of the double VM and the adapter option.

  • The enclave still validates and transforms every script before calling execute.
  • The adapter gets the usual ExecutionContext (limits, tool handler, stats, abort signal).
  • The caller owns the adapter: Enclave.dispose() doesn't dispose it, so one adapter can serve several enclaves.
  • A value without those two methods throws a TypeError at construction.

Missing node:vm. Before the double VM or the vm adapter is built, run() now fails with: @enclave-vm/core needs node:vm, which this runtime does not provide. In a browser, use @enclave-vm/browser; elsewhere, pass a sandboxAdapter (for example new InterpreterAdapter()).

Docs. adapter (JSDoc, configuration page, API reference) now says it takes effect only with doubleVm: { enabled: false }, and the worker_threads example sets that. There's a new "Custom Sandbox Adapter" section.

With this, FrontMCP's playground can pass its forwarding adapter as sandboxAdapter instead of patching getAdapter() in the published bundle.

Not changed (follow-ups)

  • adapter is still ignored while the double VM is on; now it's documented. Honoring it, or throwing, would change behavior for hosts that set adapter: 'worker_threads' today and actually run on the double VM.
  • InterpreterAdapter still only provides Math, JSON and __safe_callTool, so scripts using Date, parallel or custom globals fail on it.
  • docs/enclave/api-reference/enclave-vm.mdx documents createWorkerPoolAdapter() / createDoubleVmAdapter() factories that don't exist. Only the option rows are fixed here.

Red → green

New specs enclave.sandbox-adapter.spec.ts (8 tests) and enclave.missing-node-vm.spec.ts (3 tests, with jest.mock('vm', () => ({}))). Before: 10 failed. The one that passed is a guard: validation runs before the adapter. After: 11 passed.

Verification

  • core: jest -c libs/core/jest.config.ts --testPathIgnorePatterns /perf/: 66 suites, 2354 passed, 1 skipped; perf suite: 48 passed
  • browser e2e (whole stack): 83 passed; ast: 814 passed
  • yarn lint, yarn format:check, yarn build: pass

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Oct 3, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

Your organization has reached its usage spending cap. Adjust your spending cap in the billing tab.

Next included review available in 17 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 3 included reviews currently available. Your 43 included PR review attempts over the past 7 days set your current allowance at 3 reviews per hour.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository: agentfront/enclave/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: 9e3d3d26-bbf9-4882-978d-51e05def8a77
📥 Commits

Reviewing files that changed from the base of the PR and between f8b7c6a and 09a9518.

📒 Files selected for processing (7)
  • docs/enclave/api-reference/enclave-vm.mdx
  • docs/enclave/core-libraries/enclave-vm/configuration.mdx
  • libs/core/src/__tests__/enclave.missing-node-vm.spec.ts
  • libs/core/src/__tests__/enclave.sandbox-adapter.spec.ts
  • libs/core/src/enclave.ts
  • libs/core/src/node-vm.ts
  • libs/core/src/types.ts
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The implementation, documentation, validation, ownership semantics, and regression coverage are consistent with the stated requirements.

Review effort: Balanced
Findings: None

What changed in this PR

Adds host-supplied sandbox adapters to core while improving behavior when node:vm is unavailable.

Changes:

  • Adds validated sandboxAdapter support with caller-owned lifecycle.
  • Introduces a descriptive node:vm availability error.
  • Documents adapter precedence and adds regression tests.
File Description
libs/​core/​src/​types.ts Defines and documents sandboxAdapter.
libs/​core/​src/​node-vm.ts Checks node:vm availability.
libs/​core/​src/​enclave.ts Validates and selects host adapters.
libs/​core/​src/​__tests__/​enclave.sandbox-adapter.spec.ts Tests custom adapter behavior.
libs/​core/​src/​__tests__/​enclave.missing-node-vm.spec.ts Tests missing-VM handling.
docs/​enclave/​core-libraries/​enclave-vm/​configuration.mdx Documents configuration and examples.
docs/​enclave/​api-reference/​enclave-vm.mdx Updates the API options table.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Enclave could only run scripts with node:vm. Without it (core bundled
for a browser with vm mapped to an empty module) run() failed with
"vm.createContext is not a function", and there was no supported way
to run scripts another way: the exported InterpreterAdapter could not
be selected, and the adapter option is ignored while the double VM is
on (the default).

New sandboxAdapter option: an object with execute(code, context) and
dispose() that runs the validated, transformed script in place of the
double VM and the adapter option. The enclave does not dispose it, so
one adapter can serve several enclaves. The constructor throws a
TypeError for a value without those methods. Without node:vm, run()
now fails with "@enclave-vm/core needs node:vm, which this runtime does
not provide. In a browser, use @enclave-vm/browser; elsewhere, pass a
sandboxAdapter".

The docs now say that adapter takes effect only with the double VM off
(the worker_threads example did not disable it) and document
sandboxAdapter.

Fixes #91

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@frontegg-david
frontegg-david force-pushed the feat/core-sandbox-adapter-option branch from e47b0dc to 09a9518 Compare October 4, 2026 00:23
@frontegg-david
frontegg-david merged commit 498d317 into main Oct 4, 2026
8 checks passed
@frontegg-david
frontegg-david deleted the feat/core-sandbox-adapter-option branch October 4, 2026 10:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@enclave-vm/core: let a host supply a SandboxAdapter (Enclave can't run without node:vm, and the adapter option is ignored by default)

3 participants