mirror of
https://github.com/harivansh-afk/sandbox-agent.git
synced 2026-04-15 10:05:18 +00:00
Add support for configuring base images across all compute providers: - E2B: Accept optional `template` parameter to select custom templates - Modal: Accept optional `image` parameter (string or Image object) for base images - ComputeSDK: Expand `create` override to accept full CreateSandboxOptions payload (image, templateId, etc.) - Daytona: Improve type safety for `image` option Improve forward compatibility by making all `create` overrides accept full Partial SDK types, allowing any new provider fields to flow through without code changes. Fix Modal provider bug where `encryptedPorts` was hardcoded and would clobber user-provided values; now merges additional ports instead. Update docs and examples to demonstrate base image configuration for E2B, Modal, and ComputeSDK. Add comprehensive provider lifecycle tests for Modal and ComputeSDK, including template and image passthrough verification. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
55 lines
1.9 KiB
Text
55 lines
1.9 KiB
Text
---
|
|
title: "Modal"
|
|
description: "Deploy Sandbox Agent inside a Modal sandbox."
|
|
---
|
|
|
|
## Prerequisites
|
|
|
|
- `MODAL_TOKEN_ID` and `MODAL_TOKEN_SECRET` from [modal.com/settings](https://modal.com/settings)
|
|
- `ANTHROPIC_API_KEY` or `OPENAI_API_KEY`
|
|
|
|
## TypeScript example
|
|
|
|
```bash
|
|
npm install sandbox-agent@0.3.x modal
|
|
```
|
|
|
|
```typescript
|
|
import { SandboxAgent } from "sandbox-agent";
|
|
import { modal } from "sandbox-agent/modal";
|
|
|
|
const secrets: Record<string, string> = {};
|
|
if (process.env.ANTHROPIC_API_KEY) secrets.ANTHROPIC_API_KEY = process.env.ANTHROPIC_API_KEY;
|
|
if (process.env.OPENAI_API_KEY) secrets.OPENAI_API_KEY = process.env.OPENAI_API_KEY;
|
|
const baseImage = process.env.MODAL_BASE_IMAGE ?? "node:22-slim";
|
|
|
|
const sdk = await SandboxAgent.start({
|
|
sandbox: modal({
|
|
image: baseImage,
|
|
create: { secrets },
|
|
}),
|
|
});
|
|
|
|
try {
|
|
const session = await sdk.createSession({ agent: "claude" });
|
|
const response = await session.prompt([
|
|
{ type: "text", text: "Summarize this repository" },
|
|
]);
|
|
console.log(response.stopReason);
|
|
} finally {
|
|
await sdk.destroySandbox();
|
|
}
|
|
```
|
|
|
|
The `modal` provider handles app creation, image building, sandbox provisioning, agent installation, server startup, and tunnel networking automatically.
|
|
Set `image` to change the base Docker image before Sandbox Agent and its agent binaries are layered on top. You can also pass a prebuilt Modal `Image` object.
|
|
|
|
## Faster cold starts
|
|
|
|
Modal caches image layers, so the Dockerfile commands that install `curl` and `sandbox-agent` only run on the first build. Subsequent sandbox creates reuse the cached image.
|
|
|
|
## Notes
|
|
|
|
- Modal sandboxes use [gVisor](https://gvisor.dev/) for strong isolation.
|
|
- Ports are exposed via encrypted tunnels (`encryptedPorts`). The provider uses `sb.tunnels()` to get the public HTTPS URL.
|
|
- Environment variables (API keys) are passed as Modal [Secrets](https://modal.com/docs/guide/secrets) for security.
|