Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/images/providers/dark/sprites.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/images/providers/light/sprites.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
84 changes: 84 additions & 0 deletions src/oss/deepagents/sandboxes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,32 @@ You can also call the backend `execute()` method directly in your application co
devbox.shutdown()
```
</Tab>
<Tab title="Sprites">
<CodeGroup>
```bash pip
pip install langchain-sprites

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pip install langchain-sprites
ERROR: Could not find a version that satisfies the requirement langchain-sprites (from versions: none)

```

```bash uv
uv add langchain-sprites
```
</CodeGroup>

```python
import os

from sprites import SpritesClient

from langchain_sprites import SpritesSandbox

client = SpritesClient(os.environ["SPRITES_TOKEN"])
sprite = client.create_sprite("my-agent-sandbox")
backend = SpritesSandbox(sprite=sprite)

result = backend.execute("python --version")
print(result.output)
```
</Tab>
<Tab title="Vercel">
<CodeGroup>
```bash pip
Expand Down Expand Up @@ -648,6 +674,36 @@ Use `upload_files()` to populate the sandbox before the agent runs. Paths must b
)
```
</Tab>
<Tab title="Sprites">
<CodeGroup>
```bash pip
pip install langchain-sprites
```

```bash uv
uv add langchain-sprites
```
</CodeGroup>

```python
import os

from sprites import SpritesClient

from langchain_sprites import SpritesSandbox

client = SpritesClient(os.environ["SPRITES_TOKEN"])
sprite = client.create_sprite("my-agent-sandbox")
backend = SpritesSandbox(sprite=sprite)

backend.upload_files(
[
("/src/index.py", b"print('Hello')\n"),
("/pyproject.toml", b"[project]\nname = 'my-app'\n"),
]
)
```
</Tab>
<Tab title="Vercel">
<CodeGroup>
```bash pip
Expand Down Expand Up @@ -820,6 +876,34 @@ Use `download_files()` to retrieve files from the sandbox after the agent finish
print(f"Failed to download {result.path}: {result.error}")
```
</Tab>
<Tab title="Sprites">
<CodeGroup>
```bash pip
pip install langchain-sprites
```

```bash uv
uv add langchain-sprites
```
</CodeGroup>

```python
import os

from sprites import SpritesClient

from langchain_sprites import SpritesSandbox

client = SpritesClient(os.environ["SPRITES_TOKEN"])
sprite = client.create_sprite("my-agent-sandbox")
backend = SpritesSandbox(sprite=sprite)

results = backend.download_files(["/output/report.txt"])
for res in results:
if res.error is None:
print(res.path, res.content)
```
</Tab>
<Tab title="Vercel">
<CodeGroup>
```bash pip
Expand Down
203 changes: 203 additions & 0 deletions src/oss/javascript/integrations/providers/sprites.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
---
title: "Sprites"
sidebarTitle: "Sprites"
description: "Use Fly.io Sprites sandbox backends with deepagents for persistent sandboxes with checkpoint and restore"
---

[Fly.io Sprites](https://fly.io/sprites) provides persistent, named Linux VMs that start in 1-2 seconds, suspend automatically when idle, and support fast checkpoint and restore of the full machine state.

## Setup

<CodeGroup>
```bash npm
npm install @langchain/sprites

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

npm install @langchain/sprites
npm error code E404
npm error 404 Not Found - GET https://registry.npmjs.org/@langchain%2fsprites - Not found
npm error 404
npm error 404  The requested resource '@langchain/sprites@*' could not be found or you do not have permission to access it.
npm error 404
npm error 404 Note that you can also install from a
npm error 404 tarball, folder, http url, or git url.
npm error A complete log of this run can be found in: /Users/naomi/.npm/_logs/2026-08-31T11_09_00_588Z-debug-0.log

```

```bash yarn
yarn add @langchain/sprites
```

```bash pnpm
pnpm add @langchain/sprites
```
</CodeGroup>

### Authentication

Create an API token with the [Sprites CLI](https://docs.sprites.dev).

```bash
export SPRITES_TOKEN=your_token
```

Or pass credentials directly:

```typescript
const sandbox = await SpritesSandbox.create({
auth: { token: "your-token-here" },
});
```

## Usage with deepagents

:::js
```typescript
import { createDeepAgent } from "deepagents";
import { ChatAnthropic } from "@langchain/anthropic";
import { SpritesSandbox } from "@langchain/sprites";

const sandbox = await SpritesSandbox.create({
timeout: 300,
});

try {
const agent = createDeepAgent({
model: new ChatAnthropic({ model: "claude-sonnet-4-5" }),
systemPrompt: "You are a coding assistant with sandbox access.",
backend: sandbox,
});

const result = await agent.invoke({
messages: [{ role: "user", content: "Create a hello world script and run it" }],
});
} finally {
await sandbox.close();
}
```
:::

## Standalone usage

:::js
```typescript
import { SpritesSandbox } from "@langchain/sprites";

const sandbox = await SpritesSandbox.create();

const result = await sandbox.execute("echo hello");
console.log(result.output);

await sandbox.close();
```
:::

## Configuration

| Option | Type | Default | Description |
|--------|------|---------|-------------|
| `name` | `string` | generated | Sprite name, the sandbox's persistent identity |
| `config` | `object` | - | Machine sizing: `ramMB`, `cpus`, `region`, `storageGB` |
| `environment` | `Record<string, string>` | - | Environment variables set in the Sprite |
| `labels` | `string[]` | - | Labels for organizing sandboxes |
| `runtime` | `string` | `"default"` | Runtime image variant. Options: `"default" \| "dev"` |
| `waitForCapacity` | `boolean` | - | Wait instead of failing at the concurrency limit |
| `timeout` | `number` | `300` | Command timeout in seconds |
| `workdir` | `string` | `"/home/sprite"` | Working directory for commands and relative paths |
| `initialFiles` | `Record<string, string>` | - | Files to create on startup |
| `auth` | `object` | env vars | `{ token, baseURL }` overrides |

## Persistent sandboxes

Sprites are named and persistent. If you do not call `close()`, the Sprite suspends when idle at no cost and resumes with all files and installed packages intact:

:::js
```typescript
// Day 1
const sandbox = await SpritesSandbox.create({ name: "my-agent-env" });
await sandbox.execute("npm install express");

// Day 2: resumes in about 1 second
const sameSandbox = await SpritesSandbox.fromName("my-agent-env");
await sameSandbox.execute("node server.js");
```
:::

## Checkpoint and restore

Snapshot the full machine state before an agent run, and roll back if needed:

:::js
```typescript
const checkpoint = await sandbox.checkpoint("before agent run");

// ... let the agent make changes ...

// Roll the filesystem and process state back
await sandbox.restore(checkpoint.id);
```
:::

## Accessing the Sprites SDK

For advanced features such as services and network policy, access the underlying [Sprites SDK](https://github.com/superfly/sprites-js):

:::js
```typescript
const sandbox = await SpritesSandbox.create();
const sprite = sandbox.instance;

// Use any Sprites SDK feature directly
const checkpoints = await sprite.listCheckpoints();
const services = await sprite.listServices();
```
:::

## Factory functions

:::js
```typescript
import { createSpritesSandboxFactory, createSpritesSandboxFactoryFromSandbox } from "@langchain/sprites";

// Create a new sandbox per invocation
const factory = createSpritesSandboxFactory({ timeout: 300 });

// Or reuse an existing sandbox across invocations
const sandbox = await SpritesSandbox.create();
const reuseFactory = createSpritesSandboxFactoryFromSandbox(sandbox);
```
:::

## Error handling

```typescript
import { SpritesSandboxError } from "@langchain/sprites";

try {
await sandbox.execute("some command");
} catch (error) {
if (SpritesSandboxError.isInstance(error)) {
switch (error.code) {
case "NOT_INITIALIZED":
await sandbox.initialize();
break;
case "COMMAND_TIMEOUT":
console.error("Command took too long");
break;
case "AUTHENTICATION_FAILED":
console.error("Check your Sprites token");
break;
}
}
}
```

### Error codes

| Code | Description |
|------|-------------|
| `NOT_INITIALIZED` | Sandbox not initialized, call `initialize()` |
| `ALREADY_INITIALIZED` | Cannot initialize twice |
| `AUTHENTICATION_FAILED` | Invalid or missing Sprites token |
| `SANDBOX_CREATION_FAILED` | Failed to create the Sprite |
| `SANDBOX_NOT_FOUND` | Sprite name not found or deleted |
| `COMMAND_TIMEOUT` | Command execution timed out |
| `COMMAND_FAILED` | Command execution failed |
| `FILE_OPERATION_FAILED` | File read or write failed |
| `CHECKPOINT_FAILED` | Checkpoint or restore failed |

## Environment variables

| Variable | Description |
|----------|-------------|
| `SPRITES_TOKEN` | Sprites API token (required) |
| `SPRITES_API_URL` | Custom Sprites API URL |
6 changes: 6 additions & 0 deletions src/oss/javascript/integrations/sandboxes/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ Sandboxes provide isolated execution environments for running agent-generated co
<span className="font-semibold">Modal</span>
</a>

<a href="/oss/integrations/providers/sprites" className="flex items-center justify-center gap-1.5 p-2 rounded-lg border border-gray-200 dark:border-gray-700 hover:border-gray-300 dark:hover:border-gray-600 no-underline">
<img className="block dark:hidden w-5 h-5" src="/images/providers/light/sprites.svg" alt="" noZoom />
<img className="hidden dark:block w-5 h-5" src="/images/providers/dark/sprites.svg" alt="" noZoom />
<span className="font-semibold">Sprites</span>
</a>

<a href="https://leap0.dev/docs" className="flex items-center justify-center gap-1.5 p-2 rounded-lg border border-gray-200 dark:border-gray-700 hover:border-gray-300 dark:hover:border-gray-600 no-underline">
<img className="block dark:hidden w-5 h-5" src="/images/providers/light/leap0.svg" alt="" noZoom />
<img className="hidden dark:block w-5 h-5" src="/images/providers/dark/leap0.svg" alt="" noZoom />
Expand Down
Loading
Loading