🏖️ SandAgent

Sandbox Reuse

Reuse and persistence strategies across sandbox providers

Quick Summary

ProviderReuse MechanismPersistence
E2BName-based lookupPlatform-managed FS
SandocksandboxId optionVolume-backed
DaytonaName + volumeVolume-backed

E2B

Provide a stable name. attach() finds and resumes existing sandboxes by name.

const sandbox = new E2BSandbox({ name: "my-project", template: "base" });
const handle = await sandbox.attach();
  • Works across processes
  • Idle sandboxes may be paused and auto-resumed

Sandock

Pass a sandboxId to reuse an existing sandbox. attach() checks the sandbox status and only reattaches if it is currently RUNNING. Otherwise it creates a new one.

// Basic usage — new sandbox each time
const sandbox = new SandockSandbox({ image: "sandockai/sandock-code:latest" });
const handle = await sandbox.attach();
// Reuse via sandboxId — attach to existing sandbox
const sandbox = new SandockSandbox({
  image: "sandockai/sandock-code:latest",
  sandboxId: previousSandboxId, // obtained from handle.getSandboxId()
});
const handle = await sandbox.attach();
  • sandboxId enables cross-request reuse; callers are responsible for storing and passing it
  • Only sandboxes in RUNNING state are reused; stopped or paused sandboxes are not restarted
  • If the sandbox is not running, expired, or was deleted, attach() falls back to creating a new one
  • Volumes are resolved on both new creation and reattach

Daytona

Provide a stable name. Optional volumeName keeps files across restarts.

const sandbox = new DaytonaSandbox({
  name: "my-project",
  volumeName: "my-project-volume",
  autoStopInterval: 15,
});
const handle = await sandbox.attach();
  • Volume persists even when sandbox stops
  • Suitable for long-lived projects

Naming Strategy

Pick a stable name tied to your use case:

  • Template-based: sandagent-${template}
  • User session: user-${userId}-session-${sessionId}
  • Project: project-${projectId}

Recommendations

  • E2B: set a stable name, platform handles the rest
  • Sandock: store sandboxId from handle.getSandboxId() and pass it on next request
  • Daytona: set a stable name + volumeName for filesystem persistence across restarts

On this page