AI Docs
Chat & Streaming
Transports
Tools
Middleware
Chat UI Recipes
Interrupts
MCP
Resumable Streams
Persistence
Persistence (Advanced)
Media
Embeddings
Reranking
Evaluate
Code Mode
Computer Use
Harness
- Build your first harness
- Host options
- Send and show media
- Connect clients
- Write a client in any language
- Access and tenants
- Run in the terminal
- Deploy a harness
- Send inputs safely
- Run a tool without a model
- Durable sessions
- Run background work on workers
- List, rename, and fork sessions
- Lifecycle and retention
- Run side effects once
- Wait for a person
- Build on the session log
- Control how a turn ends
- Store settings per thread
- Compact a long session
- Fork and reset a thread
- One log for a session tree
- Write a plugin
- Track usage and cost
- Ask before risky tool calls
- Give your agent coding tools
- Sandbox and extend the coding tools
- Run the coding tools for many threads
- Undo a turn
- Build a coding agent
- Delegate to coding agents
- Switch between agent profiles
- Auth and connectors
- Share a thread between people
- Connect model providers
- Build your own UI
- Code mode in a harness
- Work until a goal is met
- Run agents from a harness
- Hand off a conversation
- Add skills
- Use MCP servers
- Give your agent a computer
- Use from any MCP client
- Use a harness from an editor (ACP)
Sandboxes
- Overview
- Quick Start
- ProvidersUpdated
- Harnesses
- Harness Auth
- Workspace
- Tools
- Policy
- Lifecycle & Snapshots
- Portable Snapshots
- Keep Files After Reload
- Save a Named Version
- Branch From a Version
- Send a Frozen File
- Let the Agent Save and Fork
- Pick Which Files to Keep
- What a Snapshot Stores
- Instance Durability
- Durable Runs
- Events
Sandboxes (Advanced)
Advanced
- Runtime Context
- Bring Your Own Key
- Keep Keys on the Server
- Debug Logging
- Multimodal Content
- Files API
- Per-Model Type Safety
- Runtime Adapter Switching
- Tree-Shaking
- Extend Adapter
- Extend Adapter: Advanced
- Typed Pre-Configured Options
- Test with a Fake Model
- Prompt Caching
- Mid-Conversation Changes
- Approval Flow Processing
AI/LLM: This documentation page is available in plain markdown format at/ai/latest/docs/sandbox/portable-snapshots-artifacts.md
Sandboxes
Send a Frozen File
snapshots.readArtifact reads the bytes of one file from a checkpoint. Return those bytes from your route.
The method makes sure that the checkpoint belongs to the supplied thread. Your route must still authorize that thread first. The method returns metadata and Uint8Array bytes. It does not create an HTTP response.
Keep this route on the server. If the session cannot access the thread, return 404. Then call snapshots.readArtifact.
ts
import { requireSession } from './auth'
import { snapshots } from './sandbox-server'
export async function GET(request: Request) {
const session = await requireSession(request)
const url = new URL(request.url)
const threadId = url.searchParams.get('threadId')
const checkpointId = url.searchParams.get('checkpointId')
const artifactId = url.searchParams.get('artifactId')
if (!threadId || !checkpointId || !artifactId) {
return new Response('Not found', { status: 404 })
}
if (!(await session.canAccessThread(threadId))) {
return new Response('Not found', { status: 404 })
}
const { artifact, bytes } = await snapshots.readArtifact({
threadId,
checkpointId,
artifactId,
})
return new Response(bytes.slice(), {
headers: {
'content-type': artifact.mimeType,
'content-length': String(artifact.size),
},
})
}The client uses the authorized route as an artifact URL. It must not read the blob store or call snapshots.readArtifact in the browser.
ts
export function snapshotArtifactUrl(
threadId: string,
checkpointId: string,
artifactId: string,
) {
const query = new URLSearchParams({ threadId, checkpointId, artifactId })
return `/api/snapshots/artifact?${query}`
}A named save copies thread artifacts into the checkpoint. Automatic restore does not change those copied bytes. See Save a Named Version and What a Snapshot Stores.