Skip to content

Commit 08a4ea3

Browse files
committed
feat: sync docs examples and matrix baselines
1 parent 2f444cb commit 08a4ea3

70 files changed

Lines changed: 2004 additions & 2014 deletions

Some content is hidden

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

CLAUDE.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,9 @@ Follow the style in `packages/secure-exec/src/index.ts`.
201201

202202
- all public-facing docs (quickstart, guides, API reference, landing page, README) must focus on the **Node.js runtime** as the primary and default experience — do not lead with WasmVM, kernel internals, or multi-runtime concepts
203203
- code examples in docs should use the `NodeRuntime` API (`runtime.run()`, `runtime.exec()`) as the default path; the kernel API (`createKernel`, `kernel.spawn()`) is for advanced multi-process use cases and should be presented as secondary
204+
- keep documentation pages and their runnable example sources in sync: `docs/quickstart.mdx` must match `examples/kitchen-sink/src/`, and `docs/features/*.mdx` must match `examples/features/src/`
205+
- when updating a doc snippet, update the corresponding example file and the docs/example verification scripts in the same change
206+
- when converting runnable example code into documentation snippets, use public package imports like `from "secure-exec"` and `from "@secure-exec/typescript"` instead of repo-local source paths
204207
- WasmVM and Python docs are experimental docs and must stay grouped under the `Experimental` section in `docs/docs.json`
205208
- docs pages that must stay current with API changes:
206209
- `docs/quickstart.mdx` — update when core setup flow changes

docs/api-reference.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ createTypeScriptTools(options: TypeScriptToolsOptions)
136136
| `runtimeDriverFactory` | `NodeRuntimeDriverFactory` | Creates the compiler sandbox runtime. |
137137
| `memoryLimit` | `number` | Compiler sandbox isolate memory cap in MB. Default `512`. |
138138
| `cpuTimeLimitMs` | `number` | Compiler sandbox CPU time budget in ms. |
139-
| `compilerSpecifier` | `string` | Module specifier used to load the TypeScript compiler. Default `"/root/node_modules/typescript/lib/typescript.js"`. |
139+
| `compilerSpecifier` | `string` | Module specifier used to load the TypeScript compiler. Default `"typescript"`. |
140140

141141
**Methods**
142142

docs/features/child-processes.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@ Sandboxed code can spawn child processes through the `CommandExecutor` interface
1212

1313
## Runnable example
1414

15+
Source file: `examples/features/src/child-processes.ts`
16+
1517
```ts
1618
import {
1719
NodeRuntime,
1820
allowAllChildProcess,
1921
createNodeDriver,
2022
createNodeRuntimeDriverFactory,
21-
} from "../../../packages/secure-exec/src/index.ts";
22-
import type { CommandExecutor } from "../../../packages/secure-exec/src/types.ts";
23+
} from "secure-exec";
24+
import type { CommandExecutor } from "secure-exec";
2325
import { spawn } from "node:child_process";
2426

2527
const commandExecutor: CommandExecutor = {
@@ -98,8 +100,6 @@ try {
98100
}
99101
```
100102

101-
Source: [examples/features/src/child-processes.ts](https://github.com/rivet-dev/secure-exec/blob/main/examples/features/src/child-processes.ts)
102-
103103
## Permission gating
104104

105105
Restrict which commands sandboxed code can spawn:

docs/features/filesystem.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@ secure-exec supports three filesystem backends. The system driver controls which
1212

1313
## Runnable example
1414

15+
Source file: `examples/features/src/filesystem.ts`
16+
1517
```ts
1618
import {
1719
NodeRuntime,
1820
allowAllFs,
1921
createInMemoryFileSystem,
2022
createNodeDriver,
2123
createNodeRuntimeDriverFactory,
22-
} from "../../../packages/secure-exec/src/index.ts";
24+
} from "secure-exec";
2325

2426
const filesystem = createInMemoryFileSystem();
2527
const runtime = new NodeRuntime({
@@ -55,8 +57,6 @@ try {
5557
}
5658
```
5759

58-
Source: [examples/features/src/filesystem.ts](https://github.com/rivet-dev/secure-exec/blob/main/examples/features/src/filesystem.ts)
59-
6060
## OPFS (browser)
6161

6262
Persistent filesystem using the Origin Private File System API. This is the default for `createBrowserDriver()`.

docs/features/module-loading.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Sandboxed code can `require()` and `import` modules through secure-exec's module
1313

1414
## Runnable example
1515

16+
Source file: `examples/features/src/module-loading.ts`
17+
1618
```ts
1719
import path from "node:path";
1820
import { fileURLToPath } from "node:url";
@@ -21,7 +23,7 @@ import {
2123
allowAllFs,
2224
createNodeDriver,
2325
createNodeRuntimeDriverFactory,
24-
} from "../../../packages/secure-exec/src/index.ts";
26+
} from "secure-exec";
2527

2628
const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../../..");
2729

@@ -58,8 +60,6 @@ try {
5860
}
5961
```
6062

61-
Source: [examples/features/src/module-loading.ts](https://github.com/rivet-dev/secure-exec/blob/main/examples/features/src/module-loading.ts)
62-
6363
## node_modules overlay
6464

6565
Node runtime executions expose a read-only dependency overlay at `/app/node_modules`, sourced from `<cwd>/node_modules` on the host (default `cwd` is `process.cwd()`).

docs/features/networking.mdx

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Network access is deny-by-default. Enable it by setting `useDefaultNetwork: true
1212

1313
## Runnable example
1414

15+
Source file: `examples/features/src/networking.ts`
16+
1517
```ts
1618
import * as http from "node:http";
1719
import {
@@ -20,7 +22,7 @@ import {
2022
createDefaultNetworkAdapter,
2123
createNodeDriver,
2224
createNodeRuntimeDriverFactory,
23-
} from "../../../packages/secure-exec/src/index.ts";
25+
} from "secure-exec";
2426

2527
const logs: string[] = [];
2628
const server = http.createServer((_req, res) => {
@@ -51,23 +53,19 @@ const runtime = new NodeRuntime({
5153
try {
5254
const result = await runtime.exec(
5355
`
54-
(async () => {
55-
const response = await fetch("http://127.0.0.1:${address.port}/");
56-
const body = await response.text();
57-
58-
if (!response.ok || response.status !== 200 || body !== "network-ok") {
59-
throw new Error(
60-
"unexpected response: " + response.status + " " + body,
61-
);
62-
}
63-
64-
console.log(JSON.stringify({ status: response.status, body }));
65-
})().catch((error) => {
66-
console.error(error instanceof Error ? error.message : String(error));
67-
process.exitCode = 1;
68-
});
56+
const response = await fetch("http://127.0.0.1:${address.port}/");
57+
const body = await response.text();
58+
59+
if (!response.ok || response.status !== 200 || body !== "network-ok") {
60+
throw new Error(
61+
"unexpected response: " + response.status + " " + body,
62+
);
63+
}
64+
65+
console.log(JSON.stringify({ status: response.status, body }));
6966
`,
7067
{
68+
filePath: "/entry.mjs",
7169
onStdio: (event) => {
7270
logs.push(`[${event.channel}] ${event.message}`);
7371
},
@@ -107,8 +105,6 @@ try {
107105
}
108106
```
109107

110-
Source: [examples/features/src/networking.ts](https://github.com/rivet-dev/secure-exec/blob/main/examples/features/src/networking.ts)
111-
112108
## Quick setup
113109

114110
<Tabs>

docs/features/output-capture.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ Console output from sandboxed code is **not buffered** into result fields. `exec
1212

1313
## Runnable example
1414

15+
Source file: `examples/features/src/output-capture.ts`
16+
1517
```ts
1618
import {
1719
NodeRuntime,
1820
createNodeDriver,
1921
createNodeRuntimeDriverFactory,
20-
} from "../../../packages/secure-exec/src/index.ts";
22+
} from "secure-exec";
2123

2224
const events: string[] = [];
2325

@@ -64,8 +66,6 @@ try {
6466
}
6567
```
6668

67-
Source: [examples/features/src/output-capture.ts](https://github.com/rivet-dev/secure-exec/blob/main/examples/features/src/output-capture.ts)
68-
6969
## Default hook
7070

7171
Set a runtime-level hook that applies to all executions:

docs/features/permissions.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ All host capabilities are **deny-by-default**. Sandboxed code cannot access the
1212

1313
## Runnable example
1414

15+
Source file: `examples/features/src/permissions.ts`
16+
1517
```ts
1618
import {
1719
NodeRuntime,
1820
createInMemoryFileSystem,
1921
createNodeDriver,
2022
createNodeRuntimeDriverFactory,
21-
} from "../../../packages/secure-exec/src/index.ts";
23+
} from "secure-exec";
2224

2325
const filesystem = createInMemoryFileSystem();
2426
await filesystem.writeFile("/secret.txt", "top secret");
@@ -69,8 +71,6 @@ console.log(
6971
);
7072
```
7173

72-
Source: [examples/features/src/permissions.ts](https://github.com/rivet-dev/secure-exec/blob/main/examples/features/src/permissions.ts)
73-
7474
## Permission helpers
7575

7676
Quick presets for common configurations:

docs/features/resource-limits.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ Resource limits prevent sandboxed code from running forever or exhausting host m
1212

1313
## Runnable example
1414

15+
Source file: `examples/features/src/resource-limits.ts`
16+
1517
```ts
1618
import {
1719
NodeRuntime,
1820
createNodeDriver,
1921
createNodeRuntimeDriverFactory,
20-
} from "../../../packages/secure-exec/src/index.ts";
22+
} from "secure-exec";
2123

2224
const runtime = new NodeRuntime({
2325
systemDriver: createNodeDriver(),
@@ -52,8 +54,6 @@ try {
5254
}
5355
```
5456

55-
Source: [examples/features/src/resource-limits.ts](https://github.com/rivet-dev/secure-exec/blob/main/examples/features/src/resource-limits.ts)
56-
5757
## CPU time limit
5858

5959
Set a CPU time budget in milliseconds. When exceeded, the execution exits with code `124`.

docs/features/typescript.mdx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@ The `@secure-exec/typescript` companion package runs the TypeScript compiler ins
1212

1313
## Runnable example
1414

15+
Source file: `examples/features/src/typescript.ts`
16+
1517
```ts
1618
import {
1719
NodeRuntime,
1820
allowAllFs,
1921
createNodeDriver,
2022
createNodeRuntimeDriverFactory,
21-
} from "../../../packages/secure-exec/src/index.ts";
22-
import { createTypeScriptTools } from "../../../packages/typescript/src/index.ts";
23+
} from "secure-exec";
24+
import { createTypeScriptTools } from "@secure-exec/typescript";
2325

2426
const sourceText = `
2527
export const message: string = "hello from typescript";
@@ -42,7 +44,7 @@ const runtime = new NodeRuntime({
4244
const ts = createTypeScriptTools({
4345
systemDriver: compilerSystemDriver,
4446
runtimeDriverFactory,
45-
compilerSpecifier: "/root/node_modules/typescript/lib/typescript.js",
47+
compilerSpecifier: "typescript",
4648
});
4749

4850
try {
@@ -91,8 +93,6 @@ try {
9193
}
9294
```
9395

94-
Source: [examples/features/src/typescript.ts](https://github.com/rivet-dev/secure-exec/blob/main/examples/features/src/typescript.ts)
95-
9696
## Install
9797

9898
```bash
@@ -119,7 +119,7 @@ const ts = createTypeScriptTools({
119119
| `runtimeDriverFactory` | `NodeRuntimeDriverFactory` | required | Creates the compiler sandbox |
120120
| `memoryLimit` | `number` | `512` | Compiler isolate memory cap in MB |
121121
| `cpuTimeLimitMs` | `number` | | Compiler CPU time budget in ms |
122-
| `compilerSpecifier` | `string` | `"/root/node_modules/typescript/lib/typescript.js"` | Module specifier for the TypeScript compiler |
122+
| `compilerSpecifier` | `string` | `"typescript"` | Module specifier for the TypeScript compiler |
123123

124124
## Type-check a source string
125125

0 commit comments

Comments
 (0)