feat(codemode): run sandboxes on Cloudflare Workers via a remote Durable Object

Split the host into transport-independent execution logic and a VM driver, so the VM can run in a worker thread (CodemodeSandbox, unchanged), on the calling thread (InlineCodemodeSandbox), or in another isolate over RPC (RemoteCodemodeSandbox).

Add the /portable entry without Node imports and the /cloudflare entry with CodemodeSandboxDurableObject, meant to be deployed as its own Worker so scripts never block the caller's thread. Scripts that compute without awaiting a tool are bounded by an interrupt budget, now also polled while draining promise jobs. examples/cloudflare shows the setup.
This commit is contained in:
Armin Ronacher 2026-10-10 14:41:36 +02:00
parent 42a3497d03
commit 748b351fe2
26 changed files with 2505 additions and 1242 deletions

View file

@ -35,7 +35,15 @@ function checkSource(source, manifest) {
function checkSpecifier(node) {
if (!node || !(isStringLiteral(node) || isNoSubstitutionTemplateLiteral(node))) return;
const specifier = node.text;
if (specifier.startsWith(".") || specifier.startsWith("/") || isBuiltin(specifier)) return;
// `cloudflare:` modules are built into the Workers runtime, like `node:` modules are into Node.
if (
specifier.startsWith(".") ||
specifier.startsWith("/") ||
specifier.startsWith("cloudflare:") ||
isBuiltin(specifier)
) {
return;
}
const name = specifier.split("/").slice(0, specifier.startsWith("@") ? 2 : 1).join("/");
if (declared.has(name)) return;
const { line } = source.getLineAndCharacterOfPosition(node.getStart(source));