Skip to content

Commit bd1620f

Browse files
committed
chore: docs
1 parent 2c2b3f5 commit bd1620f

65 files changed

Lines changed: 2916 additions & 423 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,18 +141,25 @@ V8 isolates vs. sandboxes.
141141

142142
## Secure Exec vs. Sandboxes
143143

144-
Same isolation guarantees, without the infrastructure overhead.
144+
Not every workload needs a full OS. Secure Exec gives you V8-level isolation for code execution — no container required.
145+
146+
- **Secure Exec** — Run untrusted code (Node.js, Python) inside your backend process
147+
- **Sandboxes** — Spin up a full OS with root access, system packages, and persistent disk
145148

146149
| | Secure Exec | Sandbox |
147150
|----------------------|------------------------------------------|------------------------------|
148151
| **Performance** | ✅ Native V8 | ✅ Native container |
149152
| **Permissions** | ✅ Granular deny-by-default | ❌ Coarse-grained |
150153
| **Setup** | ✅ Just `npm install` — no vendor account | ❌ Vendor account required |
151-
| **API keys** | ✅ None | ❌ Required |
152154
| **Infrastructure** | ✅ Run on any cloud or hardware | ❌ Hardware lock-in |
153155
| **Egress** | ✅ No egress fees | ❌ Per-GB egress fees |
156+
| **API keys** | ✅ None | ❌ Required |
157+
158+
[**Full comparison guide →**](https://secureexec.dev/docs/comparison/sandbox)
154159

155-
[Full comparison →](https://secureexec.dev/docs/comparison/sandbox)
160+
> **Need a full sandboxed operating system? We've got that too.** <br/>
161+
>
162+
> The [Sandbox Agent SDK](https://sandboxagent.dev/) lets you run coding agents in sandboxes and control them over HTTP. Supports Claude Code, Codex, OpenCode, Amp, and Pi. Works with E2B, Daytona, Vercel, Docker, and Cloudflare.
156163
157164
## FAQ
158165

@@ -189,22 +196,22 @@ Yes. Secure Exec supports dynamic module installation via npm inside the executi
189196
<details>
190197
<summary>Can I use it to run dev servers like Express, Hono, or Next.js?</summary>
191198

192-
Yes. Secure Exec bridges Node.js APIs including http, net, and child_process, so frameworks like Express, Hono, and Next.js work out of the box.
199+
Yes. Secure Exec bridges Node.js APIs including http, net, and child_process, so frameworks like Express, Hono, and Next.js work out of the box. For production deployments, pair Secure Exec with [Rivet Actors](https://rivet.dev/docs/actors) to get built-in routing, scaling, and lifecycle management for each server instance.
193200
</details>
194201

195202
<details>
196203
<summary>Can it be used for long-running tasks?</summary>
197204

198-
Yes. For orchestrating stateful, long-running processes efficiently, we recommend pairing Secure Exec with [Rivet Actors](https://rivet.dev/docs/actors).
205+
Yes. For orchestrating stateful, long-running tasks, we recommend pairing Secure Exec with [Rivet Actors](https://rivet.dev/docs/actors). Rivet Actors provide durable state, automatic persistence, and fault-tolerant orchestration — so each long-running task survives restarts and can be monitored, paused, or resumed without you building that infrastructure yourself.
199206
</details>
200207

201208
<details>
202209
<summary>What are common use cases?</summary>
203210

204-
- AI agent code evaluation and tool use
205-
- User-facing dev servers (Express, Hono, Next.js)
211+
- [AI agent code evaluation and tool use](https://secureexec.dev/docs/use-cases/ai-agent-code-eval)
212+
- [User-facing dev servers (Express, Hono, Next.js)](https://secureexec.dev/docs/use-cases/dev-servers)
206213
- MCP tool-code execution
207-
- Sandboxed plugin / extension systems
214+
- [Sandboxed plugin / extension systems](https://secureexec.dev/docs/use-cases/plugin-systems)
208215
- Interactive coding playgrounds
209216
</details>
210217

@@ -220,6 +227,12 @@ Yes. Most Node.js core modules work — including fs, child_process, http, dns,
220227
Yes. Secure Exec includes a virtual kernel with a system bridge that supports a granular permission model. Filesystem, network, child processes, and environment variables are all available — gated behind deny-by-default permissions.
221228
</details>
222229

230+
<details>
231+
<summary>Does Secure Exec support JIT compilation?</summary>
232+
233+
Yes. Secure Exec runs on native V8 isolates, so your code is JIT-compiled by V8's TurboFan optimizing compiler — the same pipeline that powers Chrome and Node.js. This means full optimization tiers, inline caching, and speculative optimization out of the box.
234+
</details>
235+
223236
<details>
224237
<summary>How does Secure Exec compare to WASM-based JavaScript runtimes like QuickJS?</summary>
225238

docs/api-reference.mdx

Lines changed: 14 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,18 @@ description: Complete reference for all secure-exec exports.
55

66
## Package Structure
77

8-
secure-exec is split into focused packages. The umbrella `secure-exec` package re-exports everything for convenience.
9-
108
| Package | Contents |
119
|---|---|
12-
| `@secure-exec/core` | Shared types, utilities, bridge guest code, `NodeRuntime`, `PythonRuntime` classes |
13-
| `@secure-exec/node` | Node.js V8 isolate runtime driver, `createNodeDriver`, `createNodeRuntimeDriverFactory` |
14-
| `@secure-exec/browser` | Browser Web Worker runtime driver, `createBrowserDriver`, `createBrowserRuntimeDriverFactory` |
15-
| `@secure-exec/python` | Pyodide runtime driver, `createPyodideRuntimeDriverFactory` |
10+
| `secure-exec` | Main package — `NodeRuntime`, system drivers, execution environment factories, filesystem, network, and permissions |
1611
| `@secure-exec/typescript` | Sandboxed TypeScript compiler tools |
17-
| `secure-exec` | Umbrella barrel — re-exports all of the above |
1812

1913
---
2014

2115
## Runtimes
2216

2317
### `NodeRuntime`
2418

25-
<sub>Package: `@secure-exec/core` (also re-exported from `secure-exec`)</sub>
19+
<sub>Exported from `secure-exec`</sub>
2620

2721
Sandboxed JavaScript runtime using a V8 isolate.
2822

@@ -85,41 +79,11 @@ createTypeScriptTools(options: TypeScriptToolsOptions)
8579

8680
---
8781

88-
### `PythonRuntime`
89-
90-
<sub>Package: `@secure-exec/core` (also re-exported from `secure-exec`)</sub>
91-
92-
Sandboxed Python runtime using Pyodide in a Worker thread.
93-
94-
```ts
95-
new PythonRuntime(options: PythonRuntimeOptions)
96-
```
97-
98-
**`PythonRuntimeOptions`**
99-
100-
| Option | Type | Description |
101-
|---|---|---|
102-
| `systemDriver` | `SystemDriver` | Host capabilities. **Required.** |
103-
| `runtimeDriverFactory` | `PythonRuntimeDriverFactory` | Creates the Pyodide worker. **Required.** |
104-
| `cpuTimeLimitMs` | `number` | CPU time budget in ms. |
105-
| `onStdio` | `StdioHook` | Default console output hook. |
106-
107-
**Methods**
108-
109-
| Method | Returns | Description |
110-
|---|---|---|
111-
| `exec(code, options?)` | `Promise<ExecResult>` | Execute Python code without a return value. |
112-
| `run<T>(code, options?)` | `Promise<PythonRunResult<T>>` | Execute Python code and return a value. |
113-
| `dispose()` | `void` | Release resources synchronously. |
114-
| `terminate()` | `Promise<void>` | Terminate the runtime. |
115-
116-
---
117-
11882
## System Driver Factories
11983

12084
### `createNodeDriver(options?)`
12185

122-
<sub>Package: `@secure-exec/node` (also re-exported from `secure-exec`)</sub>
86+
<sub>Exported from `secure-exec`</sub>
12387

12488
Creates a system driver for Node.js environments.
12589

@@ -142,7 +106,7 @@ createNodeDriver(options?: NodeDriverOptions): SystemDriver
142106

143107
### `createBrowserDriver(options?)`
144108

145-
<sub>Package: `@secure-exec/browser` (also re-exported from `secure-exec`)</sub>
109+
<sub>Exported from `secure-exec`</sub>
146110

147111
Creates a system driver for browser environments. Returns a promise because OPFS initialization is async.
148112

@@ -160,13 +124,13 @@ createBrowserDriver(options?: BrowserDriverOptions): Promise<SystemDriver>
160124

161125
---
162126

163-
## Runtime Driver Factories
127+
## Execution Environment Setup
164128

165129
### `createNodeRuntimeDriverFactory(options?)`
166130

167-
<sub>Package: `@secure-exec/node` (also re-exported from `secure-exec`)</sub>
131+
<sub>Re-exported from `secure-exec`</sub>
168132

169-
Creates a factory for Node.js V8 isolate runtime drivers.
133+
Creates the execution environment factory for Node.js V8 isolates. Pass the result as the `runtimeDriverFactory` option when constructing a `NodeRuntime`.
170134

171135
```ts
172136
createNodeRuntimeDriverFactory(options?: {
@@ -176,33 +140,23 @@ createNodeRuntimeDriverFactory(options?: {
176140

177141
### `createBrowserRuntimeDriverFactory(options?)`
178142

179-
<sub>Package: `@secure-exec/browser` (also re-exported from `secure-exec`)</sub>
143+
<sub>Re-exported from `secure-exec`</sub>
180144

181-
Creates a factory for browser Worker-based runtime drivers.
145+
Creates the execution environment factory for browser Worker-based sandboxes. Pass the result as the `runtimeDriverFactory` option when constructing a `NodeRuntime`.
182146

183147
```ts
184148
createBrowserRuntimeDriverFactory(options?: {
185149
workerUrl?: URL | string;
186150
}): NodeRuntimeDriverFactory
187151
```
188152

189-
### `createPyodideRuntimeDriverFactory()`
190-
191-
<sub>Package: `@secure-exec/python` (also re-exported from `secure-exec`)</sub>
192-
193-
Creates a factory for Pyodide-based Python runtime drivers.
194-
195-
```ts
196-
createPyodideRuntimeDriverFactory(): PythonRuntimeDriverFactory
197-
```
198-
199153
---
200154

201155
## Filesystem
202156

203157
### `createInMemoryFileSystem()`
204158

205-
<sub>Package: `@secure-exec/core` (also re-exported from `secure-exec`)</sub>
159+
<sub>Exported from `secure-exec`</sub>
206160

207161
Creates a fully in-memory filesystem backed by Maps.
208162

@@ -212,7 +166,7 @@ createInMemoryFileSystem(): InMemoryFileSystem
212166

213167
### `createOpfsFileSystem()`
214168

215-
<sub>Package: `@secure-exec/browser` (also re-exported from `secure-exec`)</sub>
169+
<sub>Exported from `secure-exec`</sub>
216170

217171
Creates an OPFS-backed filesystem (browser only).
218172

@@ -251,7 +205,7 @@ new NodeFileSystem()
251205

252206
### `createDefaultNetworkAdapter()`
253207

254-
<sub>Package: `@secure-exec/node` (also re-exported from `secure-exec`)</sub>
208+
<sub>Exported from `secure-exec`</sub>
255209

256210
Creates a network adapter with real fetch, DNS, and HTTP support (Node.js only).
257211

@@ -261,7 +215,7 @@ createDefaultNetworkAdapter(): NetworkAdapter
261215

262216
### `createBrowserNetworkAdapter()`
263217

264-
<sub>Package: `@secure-exec/browser` (also re-exported from `secure-exec`)</sub>
218+
<sub>Exported from `secure-exec`</sub>
265219

266220
Creates a fetch-only network adapter for browser environments. No DNS support.
267221

@@ -283,7 +237,7 @@ createBrowserNetworkAdapter(): NetworkAdapter
283237

284238
## Permissions
285239

286-
<sub>Package: `@secure-exec/core` (also re-exported from `secure-exec`)</sub>
240+
<sub>Exported from `secure-exec`</sub>
287241

288242
### Pre-built helpers
289243

@@ -336,20 +290,6 @@ Each field accepts a `PermissionCheck`, which is either a boolean or a function
336290
{ code: number; errorMessage?: string; exports?: T }
337291
```
338292

339-
### `PythonRunResult<T>`
340-
341-
```ts
342-
{ code: number; errorMessage?: string; value?: T; globals?: Record<string, unknown> }
343-
```
344-
345-
### `PythonRunOptions`
346-
347-
Extends `ExecOptions` with:
348-
349-
| Option | Type | Description |
350-
|---|---|---|
351-
| `globals` | `string[]` | Python globals to return. |
352-
353293
### `StdioHook`
354294

355295
```ts

docs/architecture.mdx

Lines changed: 8 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Every secure-exec sandbox has three layers: a **runtime** (public API), a **brid
1010
```mermaid
1111
flowchart TB
1212
subgraph Host["Host Process"]
13-
RT["Runtime<br/>(NodeRuntime / PythonRuntime)"]
13+
RT["Runtime<br/>(NodeRuntime)"]
1414
SD["System Driver<br/>(filesystem, network, processes, permissions)"]
1515
end
1616
subgraph Isolate["Sandbox"]
@@ -29,12 +29,13 @@ User code runs inside the sandbox and can only reach host capabilities through t
2929

3030
### Runtime
3131

32-
The public API. `NodeRuntime` and `PythonRuntime` are thin facades that accept a system driver and a runtime driver factory, then delegate all execution to the runtime driver.
32+
The public API. `NodeRuntime` is a thin facade that accepts a system driver, then delegates all execution to the isolate.
3333

3434
```ts
35+
import { NodeRuntime, createNodeDriver } from "secure-exec";
36+
3537
const runtime = new NodeRuntime({
3638
systemDriver: createNodeDriver(),
37-
runtimeDriverFactory: createNodeRuntimeDriverFactory(),
3839
});
3940

4041
await runtime.exec("console.log('hello')");
@@ -59,10 +60,6 @@ Each capability is wrapped in a permission layer before the bridge can call it.
5960

6061
The narrow interface between the sandbox and the host. All privileged operations pass through the bridge. It serializes requests, enforces payload size limits, and routes calls to the appropriate system driver capability.
6162

62-
### Runtime Driver
63-
64-
Manages the actual execution environment. This is where the runtime-specific isolation mechanism lives.
65-
6663
## Node Runtime
6764

6865
On Node, the sandbox is a V8 isolate managed by `isolated-vm`.
@@ -71,7 +68,6 @@ On Node, the sandbox is a V8 isolate managed by `isolated-vm`.
7168
flowchart TB
7269
subgraph Host["Host (Node.js process)"]
7370
NR["NodeRuntime"]
74-
NED["NodeExecutionDriver"]
7571
SD["System Driver"]
7672
MAFS["ModuleAccessFileSystem"]
7773
end
@@ -80,8 +76,7 @@ flowchart TB
8076
BR["Bridge (ivm.Reference callbacks)"]
8177
MOD["Module Cache"]
8278
end
83-
NR --> NED
84-
NED --> ISO
79+
NR --> ISO
8580
UC --> BR
8681
BR -->|"fs / net / process / crypto"| SD
8782
SD --> MAFS
@@ -95,7 +90,7 @@ flowchart TB
9590
- `SharedArrayBuffer` is unavailable in freeze mode
9691

9792
**Outside the isolate (host):**
98-
- `NodeExecutionDriver` creates contexts, compiles modules, and manages the isolate lifecycle
93+
- The V8 isolate execution environment creates contexts, compiles modules, and manages the isolate lifecycle
9994
- `ModuleAccessFileSystem` overlays host `node_modules` at `/app/node_modules` (read-only, blocks `.node` native addons, prevents symlink escapes)
10095
- System driver applies permission checks before every host operation
10196
- Bridge enforces payload size limits on all transfers (`ERR_SANDBOX_PAYLOAD_TOO_LARGE`)
@@ -113,15 +108,13 @@ In the browser, the sandbox is a Web Worker.
113108
flowchart TB
114109
subgraph Host["Host (browser main thread)"]
115110
NR["NodeRuntime"]
116-
BRD["BrowserRuntimeDriver"]
117111
SD["System Driver"]
118112
end
119113
subgraph WK["Web Worker"]
120114
UC["User Code (CJS / ESM)"]
121115
BR["Bridge (postMessage RPC)"]
122116
end
123-
NR --> BRD
124-
BRD -->|"postMessage"| WK
117+
NR --> WK
125118
UC --> BR
126119
BR -->|"postMessage"| SD
127120
```
@@ -133,43 +126,10 @@ flowchart TB
133126
- DNS operations return deterministic `ENOSYS` errors
134127

135128
**Outside the worker (host):**
136-
- `BrowserRuntimeDriver` spawns workers, dispatches requests by ID, and correlates responses
129+
- The browser isolate spawns workers, dispatches requests by ID, and correlates responses
137130
- `createBrowserDriver()` configures OPFS or in-memory filesystem and fetch-based networking
138131
- Node-only runtime options (like `memoryLimit`) are validated and rejected at creation time
139132

140-
## Python Runtime
141-
142-
The Python sandbox runs Pyodide in a Node Worker thread.
143-
144-
```mermaid
145-
flowchart TB
146-
subgraph Host["Host (Node.js process)"]
147-
PR["PythonRuntime"]
148-
PRD["PyodideRuntimeDriver"]
149-
SD["System Driver"]
150-
end
151-
subgraph WK["Worker Thread"]
152-
PY["Pyodide (CPython via Emscripten)"]
153-
UC["User Code (Python)"]
154-
BR["Bridge (worker RPC)"]
155-
end
156-
PR --> PRD
157-
PRD -->|"worker messages"| WK
158-
UC --> BR
159-
BR -->|"worker RPC"| SD
160-
```
161-
162-
**Inside the worker:**
163-
- Pyodide loads once and keeps interpreter state warm across runs
164-
- Python code executes with access to bridged filesystem and network
165-
- stdio streams to the host via message events
166-
167-
**Outside the worker (host):**
168-
- `PyodideRuntimeDriver` manages worker lifecycle and request correlation
169-
- Filesystem and network access goes through the same `SystemDriver` permission layer
170-
- On execution timeout, the worker state restarts for deterministic recovery
171-
- No `memoryLimit` or `timingMitigation` (Pyodide runs in a Worker, not a V8 isolate)
172-
173133
## Permission Flow
174134

175135
Every capability request follows the same path regardless of runtime:

0 commit comments

Comments
 (0)