Skip to content

Extensions

Last updated View as MarkdownAgent setup

Extensions add optional capabilities to your Sandbox subclass as nested namespaces (for example sandbox.interpreter.*). They are not free-floating globals on every app.

Attach pattern

import { Sandbox as BaseSandbox } from "@cloudflare/sandbox";
import { withInterpreter } from "@cloudflare/sandbox/interpreter";

export class Sandbox extends BaseSandbox {
	interpreter = withInterpreter(this);
}
import { Sandbox as BaseSandbox } from "@cloudflare/sandbox";
import { withInterpreter } from "@cloudflare/sandbox/interpreter";

export class Sandbox extends BaseSandbox<Env> {
	interpreter = withInterpreter(this);
}

Export that class from your Worker. Call extension methods through the nested property from application code.

First-party extensions

The following first-party extensions are available on the preview package:

Extension Package Docs
Code interpreter @cloudflare/sandbox/interpreter Code interpreter, Interpreter API
OpenCode @cloudflare/sandbox/opencode Confirm exports in your installed @next version (for example withOpenCode and client/proxy helpers).

For the interpreter, attach once, then use the same method names as the stable package (createCodeContext, runCode, and related calls) on sandbox.interpreter. Python needs the -python image variant. For the full how-to, refer to Code interpreter.

Custom extensions

Application-defined extensions are experimental. Helpers exist under @cloudflare/sandbox/extensions, but preview documentation does not yet cover authoring or publishing a custom extension. Prefer the first-party extensions in the table, or keep any custom code inside your application until a supported authoring guide ships.

Was this helpful?