Description
sablejs is a JavaScript sandbox for running untrusted code in the browser, such as user plugins, business rules, formulas or code written by an AI model. Inspired by Figma's plugin sandbox, it compiles programs ahead of time into host JavaScript instead of embedding a separate virtual machine, and it supports debugging with source maps and an inspectable compiler intermediate representation. Guest code receives copies of data and only explicitly granted capabilities: in the default sandbox mode, globals are copied so guest changes don't reach the host's objects. It compiles ES5.1 scripts, so modern code should first be downleveled with Babel or SWC. Each instance runs once and is then disposed. Examples cover Node, browser bundles, Worker isolation with timeouts, precompilation, caching, Deno and Bun. Version 2 is in beta, and its O2 optimization level is experimental.…
Highlights
- Ahead-of-time compilation to host JavaScript
- Sandbox mode that copies data into the guest
- Explicit capabilities for guest code
- Source maps and inspectable compiler IR
- Examples for Node, browsers, Workers, Deno and Bun
- TypeScript support
Ratings & Reviews
No ratings yet
Be the first to rate Sablejs.
People also visit
cloudflare/sandbox-sdk
Build sandboxed applications for secure, isolated code execution on Workers
Sablejs FAQ
What is sablejs for?
Running user-authored or AI-generated JavaScript, such as plugins, rules and formulas, safely inside a browser or other JavaScript host.
Which JavaScript version does it accept?
ES5.1 scripts with no imports that return their result as the final expression. Downlevel modern code with Babel or SWC first.
How does it keep the host safe?
In the default sandbox mode, plain globals are copied recursively, so guest mutations don't reach the host object graph, and guest code only gets capabilities you pass explicitly.
Is version 2 stable?
No, v2 is in beta and the latest npm tag stays on v1 until it is stable. O1 is the default optimization level; O2 and Os are experimental.
What are the best Sablejs alternatives?
Popular alternatives to Sablejs include Sandbox, E2B and VibeBox. See all Sablejs alternatives






