Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,11 @@ packages/core/*
website/node_modules
website/dist
website/.astro

# The docs <CodeSnippet> embeds read example source from /examples (the embed
# root is the parent of the website). Include the example source only.
!examples
examples/**/node_modules
examples/**/dist
examples/**/.astro
examples/**/target
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,4 @@ packages/core/commands/
# Transient repro scratch files and Vite/Vitest config timestamp artifacts
.tmp-*
*.timestamp-*.mjs
website/vendor/
4 changes: 4 additions & 0 deletions examples/docs/feat-module-loading/src/index.mts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { fileURLToPath } from "node:url";
import { NodeRuntime } from "secure-exec";

// docs:start loading-modules
// Boot a fully virtualized VM. Module resolution runs entirely inside the
// kernel - `import` and `require` resolve against the guest's virtual
// filesystem, never the host's.
Expand Down Expand Up @@ -38,9 +39,11 @@ try {
} finally {
await rt.dispose();
}
// docs:end loading-modules

// --- Loading real npm packages from the host ------------------------------

// docs:start npm-packages
// Point `nodeModules` at a host `node_modules` directory and the whole tree is
// projected into the VM in one call. Any package inside resolves the way Node
// would over a real filesystem, symlinks and all. Here we mount this repo's
Expand Down Expand Up @@ -83,3 +86,4 @@ try {
} finally {
await mounted.dispose();
}
// docs:end npm-packages
6 changes: 6 additions & 0 deletions examples/docs/uc-code-mode/src/index.mts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// docs:start bindings
import { NodeRuntime } from "secure-exec";

function readStringField(input: unknown, field: string): string {
Expand Down Expand Up @@ -58,7 +59,9 @@ const rt = await NodeRuntime.create({
},
},
});
// docs:end bindings

// docs:start generated-code
// Imagine this string was written by the LLM. It chains three host binding calls
// with real control flow (Promise.all, arithmetic, branching) in one execution,
// then hands a single structured result back to the host. callBinding resolves
Expand All @@ -81,7 +84,9 @@ globalThis.__return({
warmer: sf.temp_f > tokyo.temp_f ? "San Francisco" : "Tokyo",
});
`;
// docs:end generated-code

// docs:start run
interface CodeModeResult {
san_francisco: { temp_f: number };
tokyo: { temp_f: number };
Expand All @@ -102,3 +107,4 @@ try {
} finally {
await rt.dispose();
}
// docs:end run
4,187 changes: 3,714 additions & 473 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

Loading
Loading