Skip to content

Commit 4c047fe

Browse files
NathanFlurryclaude
andcommitted
docs: update architecture for V8 process isolation and add internal specs
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 75f11f9 commit 4c047fe

6 files changed

Lines changed: 1385 additions & 19 deletions

File tree

docs-internal/arch/overview.md

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@ Package index:
1818
Shared types, utilities, bridge, NodeRuntime/PythonRuntime classes,
1919
isolate-runtime source, build scripts
2020
21+
@secure-exec/v8 packages/secure-exec-v8/
22+
V8 runtime process manager (spawns Rust binary, IPC client,
23+
session abstraction). MessagePack framing over UDS.
24+
2125
@secure-exec/node packages/secure-exec-node/
22-
V8 isolate execution driver, bridge-loader, module-access overlay,
26+
Execution driver, bridge-handlers, bridge-loader, module-access overlay,
2327
createNodeDriver, createNodeRuntimeDriverFactory
2428
2529
@secure-exec/browser packages/secure-exec-browser/
@@ -116,15 +120,41 @@ Factory that builds a Python-backed execution driver factory.
116120
- Constructs `PyodideRuntimeDriver` instances
117121
- Owns Pyodide worker bootstrap and execution-driver creation options
118122

123+
## @secure-exec/v8 (V8 Runtime)
124+
125+
`packages/secure-exec-v8/`
126+
127+
Manages the Rust V8 child process and provides the session API.
128+
129+
- `createV8Runtime()` spawns the Rust binary, connects over UDS, authenticates
130+
- One Rust process is shared across all drivers (singleton)
131+
- `V8Session.execute()` sends InjectGlobals + Execute, routes BridgeCall/BridgeResponse
132+
- IPC uses length-prefixed MessagePack (64 MB max); binary data uses msgpack `bin` format (no base64)
133+
- Bridge args/results are double-encoded: inner msgpack blobs inside outer msgpack IPC messages
134+
135+
### Rust binary (`crates/v8-runtime/`)
136+
137+
The Rust V8 runtime process. One OS thread per session, each owning a `v8::Isolate`.
138+
139+
- `ipc.rs` — message types (`HostMessage`/`RustMessage`), length-prefixed framing
140+
- `isolate.rs` — V8 platform init, isolate create/destroy, heap limits
141+
- `execution.rs` — CJS (`v8::Script`) and ESM (`v8::Module`) compilation/execution, globals injection, context hardening
142+
- `bridge.rs``v8::FunctionTemplate` registration, V8↔MessagePack conversion (`v8_to_rmpv`/`rmpv_to_v8` via `rmpv::Value`)
143+
- `host_call.rs` — sync-blocking bridge calls (serialize → write → block on read → deserialize)
144+
- `stream.rs` — StreamEvent dispatch into V8 (child process, HTTP server)
145+
- `timeout.rs` — per-session timer thread, `terminate_execution()` + abort channel
146+
- `session.rs` — session management, event loop, concurrency limiting
147+
- `main.rs` — UDS listener, connection auth, signal handling, FD hygiene
148+
119149
## NodeExecutionDriver
120150

121151
`packages/secure-exec-node/src/execution-driver.ts`
122152

123-
The engine. Owns the `isolated-vm` isolate and bridges host capabilities in.
153+
The engine. Obtains a V8 session from the shared `@secure-exec/v8` runtime and bridges host capabilities in.
124154

125-
- Creates contexts, compiles ESM/CJS, runs code
126-
- Bridges fs, network, child_process, crypto, timers into the isolate via `ivm.Reference`
127-
- Caches compiled modules and resolved formats per isolate
155+
- Composes bridge code (ivm-compat shim + config + bridge bundle + timing mitigation)
156+
- Builds bridge handlers as plain functions (`bridge-handlers.ts`) passed to `V8Session.execute()`
157+
- Caches bridge code per driver instance
128158
- Enforces payload size limits on bridge transfers
129159

130160
## BrowserRuntimeDriver

0 commit comments

Comments
 (0)