Skip to content

The session's sandbox

OpenCode itself runs in the Durable Object, which has no files and no shell. A tool that needs either uses AI.Sandbox, and the harness gives each session a sandbox of its own for those tools. The session’s transcript is not in it: that is in the object’s SQLite.

An AI.Sandboxes Layer says where: E2B, Daytona, Modal, Boat or Archil. Provide it to the coding tools and the harness together:

const HarnessLive = Layer.mergeAll(
FastLive,
OpenCode.CodingTools,
OpenCodeCloudflare.DurableObjectStorage,
).pipe(Layer.provideMerge(Sandbox));

A harness whose tools use neither files nor a shell takes no AI.Sandboxes, and its sessions never open a sandbox.

A session’s sandbox opens the first time one of its tools uses AI.Sandbox. A prompt that calls only tools of yours, or none, opens nothing.

A session’s sandbox is found by a key made from the Durable Object’s id and the session’s name. session.sandboxKey is that key, for finding the sandbox on the platform yourself.

Tools run commands in the sandbox’s own working directory. cwd sets another, such as a repository your image already has. Relative paths start there too:

const harness = yield* OpenCode.Harness({
models: [Fast],
tools: [AI.CodingTools],
cwd: "/home/user/repo",
});

suspendSandbox stops the sandbox and keeps its disk, where the platform can:

yield* harness.session("pr-142").suspendSandbox;

The session’s next tool call resumes it, with its files as they were.

removeSandbox deletes the sandbox:

yield* harness.session("pr-142").removeSandbox;

The session keeps its transcript. Its next tool call that needs a sandbox starts a new one, empty.

A platform that deletes a sandbox takes the session’s files, not the session. Choose a platform that keeps a stopped sandbox’s disk when files should last. See Sandbox platforms.