Skip to main content
A resource is external state, such as a sandbox. resource() returns its handle and reuses its binding across dispatches and session turns. Checkpointing is optional. This example uses the Vercel AI SDK and the E2B driver below. Install e2b and set E2B_API_KEY for sandbox access.
agent.ts
On first use, the SDK creates the resource from its initial environment or the fork’s selected checkpoint. Later dispatches reopen the recorded binding. Session turns reuse their completed parent’s binding and start a new checkpoint count. Calls with the same key within a dispatch return the same handle. The SDK captures a baseline when checkpointing is enabled and the starting state is uncovered. Keep sandbox IDs in bindings; tool arguments and results replay across forks, which use different sandboxes.

Declaring what a step changes

resources on defineTool, wrapTool, and step() identifies what the call may change:
  • Default: none.
  • ["workspace"]: the named resource.
Tools and local steps run one at a time while an execution has resources.

Checkpoint policy

Checkpointing defaults to none. Pass a checkpoints object to enable it, including on an existing resource. Its binding is preserved. Once enabled, the policy is preserved across dispatches, session turns, and forks: Failed calls and calls cancelled after starting count. Replay, denied calls, and LLM calls do not. A due capture runs after the body and before its outcome returns. Capture failure leaves that outcome intact and the resource uncovered.

Writing a driver

Pass an object implementing ResourceDriver<Handle, Binding>: Methods can return values or promises. resource() infers the handle type from the driver. The kernel stores the JSON binding and checkpoint references; the driver stores the captured contents. Keep driverId and configuration stable for each resource key.

Fork coverage

A fork point is covered when every registered resource has matching captured state. Every event can be forked. An uncovered fork uses the newest earlier checkpoint, or the initial environment if none exists; copied results still replay and may describe changes absent from the restored state. By default, coverage ends at the next live step. A driver can set coverageReuse = true to keep it until an affecting tool or local step starts. Use this when all changes happen through declared tools and steps. A driver throws CheckpointUnavailable if the selected checkpoint is expired or missing, failing the forked execution. See Forks for the kernel flow.