Skip to content

Commit 30e92db

Browse files
committed
refactor: rename system and runtime driver contracts
1 parent 9cb32ac commit 30e92db

18 files changed

Lines changed: 213 additions & 107 deletions

File tree

docs-internal/arch/overview.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Architecture Overview
22

33
```
4-
NodeRuntime → RuntimeDriver + RuntimeExecutionDriverFactory → NodeExecutionDriver
4+
NodeRuntime → SystemDriver + RuntimeDriverFactory → NodeExecutionDriver
55
(API) (capability/config + execution wiring) (isolated-vm engine)
66
```
77

@@ -15,10 +15,10 @@ Public API. Thin facade — delegates everything to the execution driver.
1515
- `exec(code)` — execute as script, get exit code + stdout/stderr
1616
- `dispose()` / `terminate()`
1717
- Requires both:
18-
- `driver` for runtime capabilities/config
19-
- `executionFactory` for execution-driver construction
18+
- `systemDriver` for runtime capabilities/config
19+
- `runtimeDriverFactory` for runtime-driver construction
2020

21-
## RuntimeDriver
21+
## SystemDriver
2222

2323
`src/runtime-driver.ts` (re-exported from `src/types.ts`)
2424

@@ -29,26 +29,26 @@ Config object that bundles what the sandbox can access. Deny-by-default.
2929
- `commandExecutor` — child processes
3030
- `permissions` — per-adapter allow/deny checks
3131

32-
## RuntimeExecutionDriverFactory
32+
## RuntimeDriverFactory
3333

34-
Factory abstraction for constructing execution drivers from normalized runtime options.
34+
Factory abstraction for constructing runtime drivers from normalized runtime options.
3535

36-
- `createExecutionDriver(options)` — returns a `RuntimeExecutionDriver`
36+
- `createRuntimeDriver(options)` — returns a `RuntimeDriver`
3737

3838
### createNodeDriver()
3939

4040
`src/node/driver.ts`
4141

42-
Factory that builds a `RuntimeDriver` with Node-native adapters.
42+
Factory that builds a `SystemDriver` with Node-native adapters.
4343

4444
- Wraps filesystem in `ModuleAccessFileSystem` (read-only `node_modules` overlay)
4545
- Optionally wires up network and command executor
4646

47-
### createNodeExecutionFactory()
47+
### createNodeRuntimeDriverFactory()
4848

4949
`src/node/driver.ts`
5050

51-
Factory that builds a Node-backed `RuntimeExecutionDriverFactory`.
51+
Factory that builds a Node-backed `RuntimeDriverFactory`.
5252

5353
- Constructs `NodeExecutionDriver` instances
5454
- Owns optional Node-specific isolate creation hook

docs/quickstart.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ description: Get secure-exec running from TypeScript in a few minutes.
1111
</Step>
1212
<Step title="Execute code">
1313
```ts
14-
import { NodeRuntime, createNodeDriver, createNodeExecutionFactory } from "secure-exec";
14+
import { NodeRuntime, createNodeDriver, createNodeRuntimeDriverFactory } from "secure-exec";
1515

1616
const proc = new NodeRuntime({
17-
driver: createNodeDriver({}),
18-
executionFactory: createNodeExecutionFactory(),
17+
systemDriver: createNodeDriver({}),
18+
runtimeDriverFactory: createNodeRuntimeDriverFactory(),
1919
});
2020
const logs: string[] = [];
2121
const result = await proc.exec("console.log('hello from secure-exec')", {

examples/hono/loader/src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
NodeFileSystem,
99
NodeRuntime,
1010
createNodeDriver,
11-
createNodeExecutionFactory,
11+
createNodeRuntimeDriverFactory,
1212
} from "../../../../packages/secure-exec/src/index.ts";
1313
import {
1414
LOOPBACK_HOST,
@@ -33,8 +33,8 @@ function createProcess(runnerRoot: string, runnerEntry: string): NodeRuntime {
3333
});
3434

3535
return new NodeRuntime({
36-
driver,
37-
executionFactory: createNodeExecutionFactory(),
36+
systemDriver: driver,
37+
runtimeDriverFactory: createNodeRuntimeDriverFactory(),
3838
});
3939
}
4040

examples/just-bash/src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
allowAll,
44
NodeRuntime,
55
createNodeDriver,
6-
createNodeExecutionFactory,
6+
createNodeRuntimeDriverFactory,
77
type CommandExecutor,
88
type SpawnedProcess,
99
type VirtualFileSystem,
@@ -94,8 +94,8 @@ async function main(): Promise<void> {
9494
});
9595

9696
const proc = new NodeRuntime({
97-
driver,
98-
executionFactory: createNodeExecutionFactory(),
97+
systemDriver: driver,
98+
runtimeDriverFactory: createNodeRuntimeDriverFactory(),
9999
});
100100
const result = await proc.exec(`
101101
const { execSync } = require('child_process');
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
schema: spec-driven
2+
created: 2026-03-02
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
## Context
2+
3+
The runtime already separates capability/config ownership from execution construction, but terminology still causes confusion because capability-side and execution-side contracts both read as runtime concerns. This change aligns names to intent.
4+
5+
## Goals / Non-Goals
6+
7+
**Goals:**
8+
- Name capability-side contract `SystemDriver`.
9+
- Name execution-side contract `RuntimeDriver` and its factory/options accordingly.
10+
- Keep runtime behavior and security semantics unchanged.
11+
- Apply names consistently across code, tests, docs, and examples.
12+
13+
**Non-Goals:**
14+
- Changing execution semantics or permission behavior.
15+
- Reworking module loading internals.
16+
17+
## Decisions
18+
19+
1. Rename top-level contracts instead of alias-only layering.
20+
- Rationale: clear API surface and avoids perpetuating old ambiguity.
21+
22+
2. Rename constructor fields to match pair semantics.
23+
- `NodeRuntimeOptions.driver` -> `systemDriver`
24+
- `NodeRuntimeOptions.executionFactory` -> `runtimeDriverFactory`
25+
- Rationale: makes call sites self-descriptive.
26+
27+
3. Keep Node-specific execution class name as-is for now.
28+
- Rationale: scope control; core pair naming is the priority.
29+
30+
## Risks / Trade-offs
31+
32+
- [Breaking API] External call sites must update names. → Mitigation: update docs/examples/tests in the same change.
33+
- [Partial rename drift] Missed symbols can cause confusion. → Mitigation: repository-wide symbol replacement and typecheck/test validation.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
## Why
2+
3+
The current driver naming still conflates capability-side and execution-side ownership, making APIs harder to read and discuss. We want the names to map directly to responsibilities: `SystemDriver` for OS/capability simulation and `RuntimeDriver` for runtime execution management.
4+
5+
## What Changes
6+
7+
- Rename capability-side driver type from `RuntimeDriver` to `SystemDriver`.
8+
- Rename execution-side contracts from `RuntimeExecutionDriver*` to `RuntimeDriver*`.
9+
- Update Node runtime constructor and factory naming to reflect the new pair (`systemDriver` + `runtimeDriverFactory`).
10+
- Keep behavior unchanged: deny-by-default, runtime config injection, and execution semantics remain the same.
11+
- Update docs/examples/tests to use the new names.
12+
13+
## Capabilities
14+
15+
### New Capabilities
16+
- None.
17+
18+
### Modified Capabilities
19+
- `node-runtime`: API contract terminology for driver composition is renamed to `SystemDriver` (capability side) and `RuntimeDriver` (execution side) without runtime behavior changes.
20+
21+
## Impact
22+
23+
- Affected code: runtime driver typings, NodeRuntime constructor options, Node factory exports, tests/docs/examples.
24+
- API impact: **BREAKING** public type/function names and constructor option field names are renamed.
25+
- No new dependencies.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
## MODIFIED Requirements
2+
3+
### Requirement: Driver-Based Capability Composition
4+
Runtime capabilities SHALL be composed through host-provided system drivers so filesystem, network, and child-process behavior are controlled by configured adapters rather than hardcoded runtime behavior. `NodeRuntime` construction SHALL require both a capability-side `SystemDriver` and an execution-side `RuntimeDriverFactory`.
5+
6+
#### Scenario: Node runtime uses configured adapters with explicit runtime driver factory
7+
- **WHEN** `NodeRuntime` is created with a `SystemDriver` that defines filesystem, network, and command-execution adapters and with a `RuntimeDriverFactory`
8+
- **THEN** sandboxed operations MUST route through those adapters for capability access and execution MUST be created through the provided runtime driver factory
9+
10+
#### Scenario: Missing permissions deny capability access by default
11+
- **WHEN** a system driver is configured without explicit permission allowance for a capability domain
12+
- **THEN** operations in that capability domain MUST be denied by default
13+
14+
#### Scenario: Omitted capability remains unavailable
15+
- **WHEN** a capability adapter is omitted from system-driver configuration
16+
- **THEN** corresponding sandbox operations MUST be unavailable or denied by the runtime contract
17+
18+
#### Scenario: Runtime process/os config remains system-driver-owned
19+
- **WHEN** a caller provides runtime `process` and `os` configuration on the system driver
20+
- **THEN** `NodeRuntime` MUST source and inject that configuration into runtime-driver creation
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
## 1. Core Type Renames
2+
3+
- [x] 1.1 Rename capability-side `RuntimeDriver` contracts/types to `SystemDriver`.
4+
- [x] 1.2 Rename execution-side `RuntimeExecutionDriver*` contracts/types to `RuntimeDriver*`.
5+
- [x] 1.3 Update exports/re-exports to expose the new names.
6+
7+
## 2. Runtime and Node Wiring
8+
9+
- [x] 2.1 Update `NodeRuntimeOptions` and constructor fields to `systemDriver` + `runtimeDriverFactory`.
10+
- [x] 2.2 Update Node driver factory naming/typing to match new pair semantics.
11+
- [x] 2.3 Update browser typings/imports impacted by renamed contracts.
12+
13+
## 3. Documentation and Validation
14+
15+
- [x] 3.1 Update docs/examples/tests to new names.
16+
- [x] 3.2 Run targeted typecheck/tests.
17+
- [x] 3.3 Mark tasks complete and confirm OpenSpec status.

openspec/specs/node-runtime/spec.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,23 @@ The project SHALL provide a stable Node sandbox execution interface, with `NodeR
3131
- **THEN** the result's `exports` field MUST be an object containing both the `default` property and all named export properties
3232

3333
### Requirement: Driver-Based Capability Composition
34-
Runtime capabilities SHALL be composed through host-provided drivers so filesystem, network, and child-process behavior are controlled by configured adapters rather than hardcoded runtime behavior. `NodeRuntime` construction SHALL require both a capability driver and an execution factory.
34+
Runtime capabilities SHALL be composed through host-provided system drivers so filesystem, network, and child-process behavior are controlled by configured adapters rather than hardcoded runtime behavior. `NodeRuntime` construction SHALL require both a capability-side `SystemDriver` and an execution-side `RuntimeDriverFactory`.
3535

36-
#### Scenario: Node runtime uses configured adapters with explicit execution factory
37-
- **WHEN** `NodeRuntime` is created with a driver that defines filesystem, network, and command-execution adapters and with an execution factory
38-
- **THEN** sandboxed operations MUST route through those adapters for capability access and execution MUST be created through the provided factory
36+
#### Scenario: Node runtime uses configured adapters with explicit runtime driver factory
37+
- **WHEN** `NodeRuntime` is created with a `SystemDriver` that defines filesystem, network, and command-execution adapters and with a `RuntimeDriverFactory`
38+
- **THEN** sandboxed operations MUST route through those adapters for capability access and execution MUST be created through the provided runtime driver factory
3939

4040
#### Scenario: Missing permissions deny capability access by default
41-
- **WHEN** a driver is configured without explicit permission allowance for a capability domain
41+
- **WHEN** a system driver is configured without explicit permission allowance for a capability domain
4242
- **THEN** operations in that capability domain MUST be denied by default
4343

4444
#### Scenario: Omitted capability remains unavailable
45-
- **WHEN** a capability adapter is omitted from runtime configuration
45+
- **WHEN** a capability adapter is omitted from system-driver configuration
4646
- **THEN** corresponding sandbox operations MUST be unavailable or denied by the runtime contract
4747

48-
#### Scenario: Runtime process/os config remains driver-owned
49-
- **WHEN** a caller provides runtime `process` and `os` configuration on the driver
50-
- **THEN** `NodeRuntime` MUST source and inject that configuration into execution creation
48+
#### Scenario: Runtime process/os config remains system-driver-owned
49+
- **WHEN** a caller provides runtime `process` and `os` configuration on the system driver
50+
- **THEN** `NodeRuntime` MUST source and inject that configuration into runtime-driver creation
5151

5252
### Requirement: Active Handle Completion for Async Operations
5353
The Node runtime SHALL wait for tracked active handles before finalizing execution results so callback-driven asynchronous work can complete.

0 commit comments

Comments
 (0)