Skip to content

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

Open

Description

@tombeckenham

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

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions