Skip to content

Commit 4f61114

Browse files
committed
docs: audit architecture doc and glossary terminology
1 parent 55cfd27 commit 4f61114

2 files changed

Lines changed: 77 additions & 149 deletions

File tree

docs-internal/arch/overview.md

Lines changed: 73 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -1,154 +1,75 @@
11
# Architecture Overview
22

33
```
4-
Consumer API
5-
createKernel() + mount()
6-
7-
┌─────────┴─────────┐
8-
│ Kernel │ packages/kernel/
9-
│ VFS, FD Table, │
10-
│ Process Table, │
11-
│ Device Layer, │
12-
│ Pipe Manager, │
13-
│ Command Registry, │
14-
│ Permissions │
15-
└─────────┬──────────┘
16-
17-
┌──────────────┼──────────────┐
18-
│ │ │
19-
WasmVM Node Python
20-
Runtime Runtime Runtime
21-
packages/runtime/ packages/ packages/
22-
wasmvm/ secure-exec-node/ secure-exec-python/
23-
24-
@secure-exec/core packages/secure-exec-core/
25-
Shared types, utilities, bridge, NodeRuntime/PythonRuntime classes,
26-
isolate-runtime source, build scripts
27-
28-
@secure-exec/node packages/secure-exec-node/
29-
V8 isolate execution driver, bridge-loader, module-access overlay,
30-
createNodeDriver, createNodeRuntimeDriverFactory
31-
32-
@secure-exec/browser packages/secure-exec-browser/
33-
Web Worker runtime driver, createBrowserDriver,
34-
createBrowserRuntimeDriverFactory
35-
36-
@secure-exec/python packages/secure-exec-python/
37-
Pyodide runtime driver, createPyodideRuntimeDriverFactory
38-
39-
secure-exec packages/secure-exec/
40-
Barrel re-export layer — re-exports all of the above
4+
NodeRuntime / PythonRuntime
5+
packages/secure-exec-core/
6+
7+
┌────┴─────┬──────────┐
8+
│ │ │
9+
Node Browser Python
10+
packages/ packages/ packages/
11+
secure- secure- secure-
12+
exec- exec- exec-
13+
node/ browser/ python/
14+
15+
Package index:
16+
17+
@secure-exec/core packages/secure-exec-core/
18+
Shared types, utilities, bridge, NodeRuntime/PythonRuntime classes,
19+
isolate-runtime source, build scripts
20+
21+
@secure-exec/node packages/secure-exec-node/
22+
V8 isolate execution driver, bridge-loader, module-access overlay,
23+
createNodeDriver, createNodeRuntimeDriverFactory
24+
25+
@secure-exec/browser packages/secure-exec-browser/
26+
Web Worker execution driver, createBrowserDriver,
27+
createBrowserRuntimeDriverFactory
28+
29+
@secure-exec/python packages/secure-exec-python/
30+
Pyodide execution driver, createPyodideRuntimeDriverFactory
31+
32+
@secure-exec/typescript packages/secure-exec-typescript/
33+
Optional TypeScript compiler tools (type-checking, compilation)
34+
35+
secure-exec packages/secure-exec/
36+
Barrel re-export layer (re-exports core, node, browser, python)
4137
```
4238

43-
## Kernel
44-
45-
`packages/kernel/src/`
46-
47-
The shared OS layer. Platform-agnostic — no Node.js or browser APIs. All runtimes make "syscalls" to the kernel for filesystem, process, pipe, and FD operations.
48-
49-
- `createKernel(options)` — creates a kernel with a VFS backend and optional permissions
50-
- `kernel.mount(driver)` — mounts a runtime driver, registers its commands
51-
- `kernel.exec(command)` — executes through the shell (requires WasmVM runtime)
52-
- `kernel.spawn(command, args)` — spawns a process directly via command registry
53-
54-
### Kernel Components
55-
56-
- **VFS** (`vfs.ts`) — POSIX-complete `VirtualFileSystem` interface with symlinks, links, chmod/chown/utimes/truncate
57-
- **FD Table** (`fd-table.ts`) — Per-PID file descriptors with shared FileDescriptions (cursor sharing via dup/dup2)
58-
- **Process Table** (`process-table.ts`) — PID allocation, parent-child, waitpid, signal routing across runtimes
59-
- **Device Layer** (`device-layer.ts`) — Intercepts /dev/null, /dev/zero, /dev/stdin, /dev/stdout, /dev/stderr, /dev/urandom
60-
- **Pipe Manager** (`pipe-manager.ts`) — Cross-runtime pipe creation and buffered data flow
61-
- **Command Registry** (`command-registry.ts`) — Command name → driver routing, /bin population for shell PATH lookup
62-
- **Permissions** (`permissions.ts`) — Deny-by-default VFS permission wrapping
63-
- **User** (`user.ts`) — User/group identity (uid, gid, getpwuid)
64-
65-
### RuntimeDriver Interface
66-
67-
```typescript
68-
interface RuntimeDriver {
69-
name: string;
70-
commands: string[];
71-
init(kernel: KernelInterface): Promise<void>;
72-
spawn(command: string, args: string[], ctx: ProcessContext): DriverProcess;
73-
dispose(): Promise<void>;
74-
}
75-
```
76-
77-
## OS Layer
78-
79-
Platform-specific implementations of abstractions the kernel needs.
80-
81-
### os/node
82-
83-
`packages/os/node/src/`
84-
85-
- `NodeFileSystem` — implements `VirtualFileSystem` by delegating to `node:fs/promises`
86-
- `NodeWorkerAdapter` — wraps `node:worker_threads`
87-
88-
### os/browser
89-
90-
`packages/os/browser/src/`
91-
92-
- `InMemoryFileSystem` — POSIX-complete in-memory VFS with symlinks, hard links, permissions
93-
- `BrowserWorkerAdapter` — wraps Web Worker API
94-
95-
## WasmVM Runtime
96-
97-
`packages/runtime/wasmvm/src/` (TypeScript host) + `wasmvm/` (Rust workspace)
98-
99-
BusyBox-style WASM binary containing 90+ Unix commands (brush-shell, coreutils, grep, sed, awk, find, jq).
100-
101-
- `WasmOS` class — current standalone API (pre-kernel integration)
102-
- WASI polyfill (46 syscalls) → translates WASI calls to VFS/FD/process operations
103-
- Worker-based process model with SharedArrayBuffer + Atomics synchronization
104-
- Ring buffers for WASM-to-WASM pipeline optimization
105-
106-
## Existing Runtime Architecture
107-
108-
The runtime is split across `@secure-exec/core` (shared types and runtime classes), `@secure-exec/node`, `@secure-exec/browser`, and `@secure-exec/python`. The `secure-exec` barrel package re-exports everything. The kernel is additive.
109-
110-
### NodeRuntime / PythonRuntime
39+
## NodeRuntime / PythonRuntime
11140

11241
`packages/secure-exec-core/src/runtime.ts`, `packages/secure-exec-core/src/python-runtime.ts`
11342

114-
Public APIs. Thin facades that delegate orchestration to runtime drivers.
43+
Public APIs. Thin facades that delegate orchestration to execution drivers.
11544

11645
- `NodeRuntime.run(code)` — execute JS module, get exports back
11746
- `PythonRuntime.run(code)` — execute Python and return structured value/global wrapper
11847
- `exec(code)` — execute as script, get exit code/error contract
11948
- `dispose()` / `terminate()`
12049
- Requires both:
12150
- `systemDriver` for runtime capabilities/config
122-
- runtime-driver factory for runtime-driver construction
123-
124-
### TypeScript Tools
125-
126-
`packages/secure-exec-typescript/src/index.ts`
127-
128-
Optional companion package for sandboxed TypeScript compiler work (`@secure-exec/typescript`).
129-
130-
- `createTypeScriptTools(...)` — build project/source compile and typecheck helpers
131-
- Uses a dedicated `NodeRuntime` compiler sandbox per request
132-
- Keeps TypeScript compiler execution out of the core runtime path
51+
- runtime-driver factory for execution-driver construction
13352

134-
### SystemDriver
53+
## SystemDriver
13554

13655
`packages/secure-exec-core/src/types.ts`
13756

138-
Config object that bundles what the sandbox can access. Deny-by-default.
57+
Config object that bundles what the isolate can access. Deny-by-default.
13958

14059
- `filesystem` — VFS adapter
14160
- `network` — fetch, DNS, HTTP
14261
- `commandExecutor` — child processes
14362
- `permissions` — per-adapter allow/deny checks
14463

145-
### NodeRuntimeDriverFactory / PythonRuntimeDriverFactory
64+
## NodeRuntimeDriverFactory / PythonRuntimeDriverFactory
14665

147-
Factory abstraction for constructing runtime drivers from normalized runtime options.
66+
`packages/secure-exec-core/src/runtime-driver.ts`
14867

149-
- `createRuntimeDriver(options)` — returns a `RuntimeDriver`
68+
Factory abstraction for constructing execution drivers from normalized runtime options.
15069

151-
#### createNodeDriver()
70+
- `createRuntimeDriver(options)` — returns an execution driver
71+
72+
### createNodeDriver()
15273

15374
`packages/secure-exec-node/src/driver.ts`
15475

@@ -157,16 +78,16 @@ Factory that builds a `SystemDriver` with Node-native adapters.
15778
- Wraps filesystem in `ModuleAccessFileSystem` (read-only `node_modules` overlay)
15879
- Optionally wires up network and command executor
15980

160-
#### createNodeRuntimeDriverFactory()
81+
### createNodeRuntimeDriverFactory()
16182

16283
`packages/secure-exec-node/src/driver.ts`
16384

164-
Factory that builds a Node-backed `RuntimeDriverFactory`.
85+
Factory that builds a Node-backed execution driver factory.
16586

16687
- Constructs `NodeExecutionDriver` instances
16788
- Owns optional Node-specific isolate creation hook
16889

169-
#### createBrowserDriver()
90+
### createBrowserDriver()
17091

17192
`packages/secure-exec-browser/src/driver.ts`
17293

@@ -176,26 +97,26 @@ Factory that builds a browser `SystemDriver` with browser-native adapters.
17697
- Uses fetch-backed network adapter with deterministic `ENOSYS` for unsupported DNS/server paths
17798
- Applies permission wrappers before returning the driver
17899

179-
#### createBrowserRuntimeDriverFactory()
100+
### createBrowserRuntimeDriverFactory()
180101

181102
`packages/secure-exec-browser/src/runtime-driver.ts`
182103

183-
Factory that builds a browser-backed `RuntimeDriverFactory`.
104+
Factory that builds a browser-backed execution driver factory.
184105

185106
- Validates and rejects Node-only runtime options
186107
- Constructs `BrowserRuntimeDriver` instances
187-
- Owns worker URL/runtime-driver creation options
108+
- Owns worker URL/execution-driver creation options
188109

189-
#### createPyodideRuntimeDriverFactory()
110+
### createPyodideRuntimeDriverFactory()
190111

191112
`packages/secure-exec-python/src/driver.ts`
192113

193-
Factory that builds a Python-backed `PythonRuntimeDriverFactory`.
114+
Factory that builds a Python-backed execution driver factory.
194115

195116
- Constructs `PyodideRuntimeDriver` instances
196-
- Owns Pyodide worker bootstrap and runtime-driver creation options
117+
- Owns Pyodide worker bootstrap and execution-driver creation options
197118

198-
### NodeExecutionDriver
119+
## NodeExecutionDriver
199120

200121
`packages/secure-exec-node/src/execution-driver.ts`
201122

@@ -206,7 +127,7 @@ The engine. Owns the `isolated-vm` isolate and bridges host capabilities in.
206127
- Caches compiled modules and resolved formats per isolate
207128
- Enforces payload size limits on bridge transfers
208129

209-
### BrowserRuntimeDriver
130+
## BrowserRuntimeDriver
210131

211132
`packages/secure-exec-browser/src/runtime-driver.ts`
212133

@@ -221,14 +142,14 @@ Browser execution driver that owns worker lifecycle and message marshalling.
221142

222143
`packages/secure-exec-browser/src/worker.ts`
223144

224-
Worker-side runtime implementation used by the browser runtime driver.
145+
Worker-side runtime implementation used by the browser execution driver.
225146

226147
- Initializes browser bridge globals and runtime config from worker init payload
227148
- Executes transformed CJS/ESM user code and returns runtime-contract results
228149
- Uses permission-aware filesystem/network adapters in the worker context
229150
- Preserves deterministic unsupported-operation contracts (for example DNS gaps)
230151

231-
### PyodideRuntimeDriver
152+
## PyodideRuntimeDriver
232153

233154
`packages/secure-exec-python/src/driver.ts`
234155

@@ -240,7 +161,17 @@ Python execution driver that owns a Node worker running Pyodide.
240161
- Uses worker-to-host RPC for permission-wrapped filesystem/network access through `SystemDriver`
241162
- Restarts worker state on execution timeout to preserve deterministic recovery behavior
242163

243-
### ModuleAccessFileSystem
164+
## TypeScript Tools
165+
166+
`packages/secure-exec-typescript/src/index.ts`
167+
168+
Optional companion package for isolated TypeScript compiler work (`@secure-exec/typescript`).
169+
170+
- `createTypeScriptTools(...)` — build project/source compile and typecheck helpers
171+
- Uses a dedicated `NodeRuntime` isolate per request
172+
- Keeps TypeScript compiler execution out of the core runtime path
173+
174+
## ModuleAccessFileSystem
244175

245176
`packages/secure-exec-node/src/module-access.ts`
246177

@@ -250,11 +181,15 @@ Filesystem overlay that makes host `node_modules` available read-only at `/root/
250181
- Prevents symlink escapes (resolves pnpm virtual-store paths)
251182
- Non-module paths fall through to base VFS
252183

253-
### Permissions
184+
## Permissions
254185

255186
`packages/secure-exec-core/src/shared/permissions.ts`
256187

257188
Wraps each adapter with allow/deny checks before calls reach the host.
258189

259190
- `wrapFileSystem()`, `wrapNetworkAdapter()`, `wrapCommandExecutor()`
260191
- Missing adapters get deny-all stubs
192+
193+
---
194+
195+
> **Kernel packages** (`packages/kernel/`, `packages/runtime/`, `packages/os/`) are experimental and not part of the public API. See `wasmvm/CLAUDE.md` for kernel and WasmVM architecture details.

docs-internal/glossary.md

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
11
# Glossary
22

3-
- **Kernel** — the shared OS layer (`packages/kernel/`). Provides VFS, FD table, process table, device layer, pipes, command registry, and permissions. All runtimes share the same kernel instance.
4-
- **Runtime Driver** — a pluggable execution engine (WasmVM, Node, Python) that implements the `RuntimeDriver` interface and mounts into the kernel. Registers commands and spawns processes.
5-
- **WasmVM** — the BusyBox-style WASM binary runtime. Contains 90+ Unix commands compiled from Rust. Runs in Web Workers with WASI polyfill.
6-
- **Isolate** — a V8 isolate. The unit of code execution and memory isolation. Each sandbox execution gets its own isolate.
7-
- **Runtime** — the sandbox. The full `secure-exec` execution environment including the isolate, bridge, and resource controls.
3+
- **Isolate** — a V8 isolate (Node/Bun) or Web Worker (browser). The unit of code execution and memory isolation. Each execution gets its own isolate.
4+
- **Runtime** — the full `secure-exec` execution environment including the isolate, bridge, and resource controls. `NodeRuntime` and `PythonRuntime` are the public entry points.
85
- **Bridge** — the narrow layer between the isolate and the host that mediates all privileged operations. Untrusted code can only reach host capabilities through the bridge.
9-
- **Driver** — a host-side capability provider (filesystem, network, process, env) that the bridge delegates to. Drivers are configured per-sandbox and enforce permission checks.
10-
- **VFS** — virtual filesystem. The kernel's `VirtualFileSystem` interface, implemented by platform-specific backends (NodeFileSystem, InMemoryFileSystem).
11-
- **FD Table** — per-PID file descriptor table. Maps FD numbers to `FileDescription` objects with shared cursor positions via dup/dup2.
12-
- **Process Table** — tracks all processes across runtimes. Owns PID allocation, parent-child relationships, waitpid, and signal routing.
13-
- **Command Registry** — maps command names to runtime drivers. Enables shell PATH lookup and cross-runtime command execution.
14-
- **Device Layer** — intercepts `/dev/*` paths before they reach the VFS backend. Handles `/dev/null`, `/dev/zero`, `/dev/urandom`, `/dev/stdin`, `/dev/stdout`, `/dev/stderr`.
6+
- **SystemDriver** — config object that bundles what the isolate can access (filesystem, network, command executor, permissions). Deny-by-default. Built by `createNodeDriver()` or `createBrowserDriver()`.
7+
- **Execution Driver** — host-side engine that owns the isolate lifecycle. `NodeExecutionDriver` (V8 via `isolated-vm`), `BrowserRuntimeDriver` (Web Worker), `PyodideRuntimeDriver` (Pyodide in a Node worker).

0 commit comments

Comments
 (0)