---
title: Server Sandbox Architecture
description: Cloud sandbox integration for production deployments
---

## Why Server Sandboxes

| Aspect | LocalSandbox | Server Sandbox |
|--------|-------------|----------------|
| Isolation | Local process | Isolated containers |
| Access to user code | Possible | Fully isolated |
| Resource control | Shared | Dedicated CPU/memory |
| Persistence | Local filesystem | Volume or platform-managed |
| Best for | Development | Production |

## High-Level Architecture

```
Client (Web UI / CLI)
    ↓ HTTP Stream
Server (Next.js API → SandAgent SDK → Sandbox Adapter)
    ↓ exec
Cloud Sandbox (sandagent CLI → Claude Agent SDK → /workspace)
```

## Supported Providers

All providers implement the same `SandboxAdapter` contract.

### E2B

```typescript
import { E2BSandbox } from "@sandagent/sandbox-e2b";

const sandbox = new E2BSandbox({
  template: "sandagent-claude-researcher",
  timeout: 3600,
  name: "my-agent",
  workdir: "/workspace",
  env: { ANTHROPIC_API_KEY: process.env.ANTHROPIC_API_KEY! },
});
```

### Daytona

```typescript
import { DaytonaSandbox } from "@sandagent/sandbox-daytona";

const sandbox = new DaytonaSandbox({
  snapshot: "sandagent-claude-researcher:0.1.0",
  name: "my-agent",
  volumeName: "my-agent-volume",
  autoStopInterval: 15,
  workdir: "/workspace",
  env: { ANTHROPIC_API_KEY: process.env.ANTHROPIC_API_KEY! },
});
```

### Sandock

```typescript
import { SandockSandbox } from "@sandagent/sandbox-sandock";

const sandbox = new SandockSandbox({
  image: "sandockai/sandock-code:latest",
  memoryLimitMb: 2048,
  cpuShares: 2,
  workdir: "/workspace",
  env: { ANTHROPIC_API_KEY: process.env.ANTHROPIC_API_KEY! },
});
```

## SDK Integration Example

```typescript
import { createSandAgent } from "@sandagent/sdk";
import { E2BSandbox } from "@sandagent/sandbox-e2b";
import { streamText } from "ai";

const sandbox = new E2BSandbox({
  template: "sandagent-claude-researcher",
  workdir: "/workspace",
  env: { ANTHROPIC_API_KEY: process.env.ANTHROPIC_API_KEY! },
});

const sandagent = createSandAgent({ sandbox });

const result = streamText({
  model: sandagent("claude-sonnet-4-20250514"),
  prompt: "Write a Python crawler and run it",
});

for await (const chunk of result.textStream) {
  process.stdout.write(chunk);
}
```

## Troubleshooting

| Issue | Cause | Fix |
|-------|-------|-----|
| `Invalid API key` | Missing provider key | Check env vars |
| `Template not found` | Not deployed | Deploy with `make e2b/daytona` |
| Timeout | Long-running task | Increase `timeout` |
