HEX
Server: Apache/2.4.46 (Win64) OpenSSL/1.1.1j PHP/8.4.25
System: Windows NT DESKTOP-4TAV2RJ 10.0 build 19045 (Windows 10) AMD64
User: fred (0)
PHP: 8.4.25
Disabled: NONE
Upload Files
File: C:/Users/fred/.codex/.tmp/plugins/plugins/cloudflare/skills/sandbox-sdk/references/examples.md
# Sandbox SDK Examples

All examples: https://github.com/cloudflare/sandbox-sdk/tree/main/examples

## Example Index

| Example | Use Case | Key File |
|---------|----------|----------|
| `minimal` | Basic setup, exec, file ops | `src/index.ts` |
| `code-interpreter` | AI code execution with Workers AI | `src/index.ts` |
| `openai-agents` | OpenAI Agents SDK integration | `src/index.ts` |
| `opencode` | OpenCode agent integration | `src/index.ts` |
| `codex-app-server` | Codex app server integration | `src/index.ts` |
| `typescript-validator` | TypeScript compilation/validation | `src/index.ts` |
| `authentication` | Auth patterns for sandboxes | `src/index.ts` |

## When to Use Which Example

| Building | Start With |
|----------|------------|
| AI code execution | `code-interpreter` |
| Agent with shell + file editing | `openai-agents` |
| Basic command execution | `minimal` |
| Code validation service | `typescript-validator` |
| Multi-user sandboxes | `authentication` |

## Common Patterns from Examples

**Sandbox per user/session** (from `openai-agents`):
```typescript
const sandbox = getSandbox(env.Sandbox, `session-${sessionId}`);
```

**Code context reuse** (from `code-interpreter`):
```typescript
const pythonCtx = await sandbox.createCodeContext({ language: 'python' });
const result = await sandbox.runCode(code, { context: pythonCtx });
```

**Resource cleanup** (from `code-interpreter`):
```typescript
try {
  // ... use sandbox
} finally {
  await sandbox.destroy();
}
```

Fetch the full example source when implementing similar patterns.