Skip to content
Source
Sign inSign up
TanStack/ai

ai-sandbox-cloudflare: upgrade @cloudflare/sandbox to 1.x for container snapshots #1983

Send to my agent
Opentombeckenham opened this issue 0 comments
tombeckenhamcommented

Upgrade @cloudflare/sandbox from ^0.12.1 to 1.x in @tanstack/ai-sandbox-cloudflare and in examples/sandbox-cloudflare. Cloudflare now documents 0.x only "for existing applications".

Why

Sandbox SDK 1.0 lets your own Durable Object control each container through ctx.container, with the durable_object scheduling policy. That unlocks features that our provider cannot use today:

  1. Container snapshots. ctx.container.snapshotContainer() saves the whole container disk. ctx.container.start({ containerSnapshot }) restores it. Snapshots live 30 days, and each restore renews them. With this, the provider can set snapshots: true and implement handle.snapshot() and restoreSnapshot(). Today it declares snapshots: false and durableFilesystem: false.
  2. Directory backups without R2 keys. In 1.0, DirectoryBackup sends backups through a DirectoryBackupGateway in the Worker. The container gets no R2 credentials. In 0.12, createBackup() needs R2 API keys as Worker secrets.
  3. Instance size per container. start({ instance }) picks the size at runtime. In 0.12, one instance_type applies to the whole app.

Context

  • PR #1982 benchmarked the provider for computer use. A standard-4 container took about 180 ms for each command. The disk is wiped on each restart, so a signed-in browser does not survive. Snapshots fix that second part.
  • PR #1982 also fixed a bug in the provider. 0.12 runs every command in one shared shell, so a command that called exit ended the session. When we migrate, check how 1.0 runs commands, and keep the subshell wrap if it is still needed.

Work

  1. Read the migration guide: https://developers.cloudflare.com/sandbox/sdk/migrate/
  2. Move the provider to 1.0. The 0.12 Sandbox class is replaced by your own Durable Object class.
  3. Set snapshots: true and implement container snapshots. Guide: https://developers.cloudflare.com/containers/guides/snapshots/
  4. Update examples/sandbox-cloudflare and its Dockerfile base tag.
  5. Update docs/ for the provider (setup, the durable_object policy, snapshots).

References

Sign in to join this conversation.