---
title: Sandbox Reuse
description: Reuse and persistence strategies across sandbox providers
---

## Quick Summary

| Provider | Reuse Mechanism | Persistence |
|----------|----------------|-------------|
| E2B | Name-based lookup | Platform-managed FS |
| Sandock | `sandboxId` option | Volume-backed |
| Daytona | Name + volume | Volume-backed |

## E2B

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

```typescript
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.

```typescript
// Basic usage — new sandbox each time
const sandbox = new SandockSandbox({ image: "sandockai/sandock-code:latest" });
const handle = await sandbox.attach();
```

```typescript
// 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.

```typescript
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
