Skip to content

Commit a5d42a2

Browse files
authored
docs: add sandbox agents guides (#1200)
1 parent 84ba9f1 commit a5d42a2

34 files changed

Lines changed: 1403 additions & 30 deletions

README.md

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
# OpenAI Agents SDK (JavaScript/TypeScript)
22

3-
[![npm version](https://badge.fury.io/js/@openai%2Fagents.svg)](https://badge.fury.io/js/@openai%2Fagents)
4-
[![CI](https://github.com/openai/openai-agents-js/actions/workflows/test.yml/badge.svg)](https://github.com/openai/openai-agents-js/actions/workflows/test.yml)
3+
[![npm version](https://badge.fury.io/js/@openai%2Fagents.svg)](https://badge.fury.io/js/@openai%2Fagents) [![CI](https://github.com/openai/openai-agents-js/actions/workflows/test.yml/badge.svg)](https://github.com/openai/openai-agents-js/actions/workflows/test.yml)
54

65
The OpenAI Agents SDK is a lightweight yet powerful framework for building multi-agent workflows in JavaScript/TypeScript. It is provider-agnostic, supporting OpenAI APIs and more.
76

87
<img src="https://cdn.openai.com/API/docs/images/orchestration.png" alt="Image of the Agents Tracing UI" style="max-height: 803px;">
98

10-
> [!NOTE]
11-
> Looking for the Python version? Check out [OpenAI Agents SDK Python](https://github.com/openai/openai-agents-python).
9+
> [!NOTE] Looking for the Python version? Check out [OpenAI Agents SDK Python](https://github.com/openai/openai-agents-python).
1210
1311
## Core concepts
1412

1513
1. [**Agents**](https://openai.github.io/openai-agents-js/guides/agents): LLMs configured with instructions, tools, guardrails, and handoffs
14+
1. [**Sandbox Agents**](https://openai.github.io/openai-agents-js/guides/sandbox-agents): Agents paired with a filesystem workspace and sandbox environment for longer-running work
1615
1. **[Agents as tools](https://openai.github.io/openai-agents-js/guides/tools/#4-agents-as-tools) / [Handoffs](https://openai.github.io/openai-agents-js/guides/handoffs/)**: Delegating to other agents for specific tasks
1716
1. [**Tools**](https://openai.github.io/openai-agents-js/guides/tools/): Various Tools let agents take actions (functions, MCP, hosted tools)
1817
1. [**Guardrails**](https://openai.github.io/openai-agents-js/guides/guardrails/): Configurable safety checks for input and output validation
@@ -43,7 +42,47 @@ Explore the [`examples/`](https://github.com/openai/openai-agents-js/tree/main/e
4342
npm install @openai/agents zod
4443
```
4544

46-
### Run your first agent
45+
### Run your first Sandbox Agent
46+
47+
[Sandbox Agents](https://openai.github.io/openai-agents-js/guides/sandbox-agents) are in beta. A sandbox agent can inspect files, run commands, apply patches, and carry workspace state across longer tasks.
48+
49+
```js
50+
import { run } from '@openai/agents';
51+
import { gitRepo, Manifest, SandboxAgent } from '@openai/agents/sandbox';
52+
import { UnixLocalSandboxClient } from '@openai/agents/sandbox/local';
53+
54+
const agent = new SandboxAgent({
55+
name: 'Workspace Assistant',
56+
instructions: 'Inspect the sandbox workspace before answering.',
57+
defaultManifest: new Manifest({
58+
entries: {
59+
repo: gitRepo({
60+
repo: 'openai/openai-agents-js',
61+
ref: 'main',
62+
}),
63+
},
64+
}),
65+
});
66+
67+
const result = await run(
68+
agent,
69+
'Inspect repo/README.md and summarize what this project does.',
70+
{
71+
sandbox: {
72+
client: new UnixLocalSandboxClient(),
73+
},
74+
},
75+
);
76+
77+
console.log(result.finalOutput);
78+
// This project provides a JavaScript/TypeScript SDK for building agent workflows.
79+
```
80+
81+
(_If running this, ensure you set the `OPENAI_API_KEY` environment variable_)
82+
83+
### Run an agent without a sandbox
84+
85+
You can still use a regular `Agent` when your workflow does not need a filesystem workspace or sandbox lifecycle.
4786

4887
```js
4988
import { Agent, run } from '@openai/agents';
@@ -63,8 +102,6 @@ console.log(result.finalOutput);
63102
// Infinite loop's dance.
64103
```
65104

66-
(_If running this, ensure you set the `OPENAI_API_KEY` environment variable_)
67-
68105
Explore the [`examples/`](https://github.com/openai/openai-agents-js/tree/main/examples) directory to see the SDK in action.
69106

70107
## Acknowledgements

docs/astro.config.mjs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,27 @@ const sidebar = [
136136
ko: '에이전트',
137137
},
138138
},
139+
{
140+
label: 'Sandbox agents',
141+
items: [
142+
{
143+
label: 'Quickstart',
144+
link: '/guides/sandbox-agents',
145+
},
146+
{
147+
label: 'Concepts',
148+
link: '/guides/sandbox-agents/concepts',
149+
},
150+
{
151+
label: 'Sandbox clients',
152+
link: '/guides/sandbox-agents/clients',
153+
},
154+
{
155+
label: 'Agent memory',
156+
link: '/guides/sandbox-agents/memory',
157+
},
158+
],
159+
},
139160
{
140161
label: 'Models',
141162
link: '/guides/models',
84.2 KB
Loading

docs/src/components/Hero.astro

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
import { Code, TabItem, Tabs } from '@astrojs/starlight/components';
3+
import helloWorldSandboxExample from '../../../examples/docs/toppage/sandboxAgent.ts?raw';
34
import helloWorldExample from '../../../examples/docs/toppage/textAgent.ts?raw';
45
import helloWorldVoiceExample from '../../../examples/docs/toppage/voiceAgent.ts?raw';
56
const path = Astro.url.pathname;
@@ -22,6 +23,9 @@ const pathPrefix =
2223
</div>
2324
<div class="openai-hero-code flex-1 overflow-x-scroll">
2425
<Tabs>
26+
<TabItem label="Sandbox Agent">
27+
<Code lang="typescript" code={helloWorldSandboxExample} />
28+
</TabItem>
2529
<TabItem label="Text Agent">
2630
<Code lang="typescript" code={helloWorldExample} />
2731
</TabItem>

docs/src/content/docs/guides/agents.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Use this page as the hub for agent definition. Jump out to the adjacent guide th
3434
| --- | --- |
3535
| Choose a model or configure stored prompts | [Models](/openai-agents-js/guides/models) |
3636
| Add capabilities to the agent | [Tools](/openai-agents-js/guides/tools) |
37+
| Give the agent an isolated filesystem workspace | [Sandbox agents](/openai-agents-js/guides/sandbox-agents/concepts) |
3738
| Decide between managers and handoffs | [Agent orchestration](/openai-agents-js/guides/multi-agent) |
3839
| Configure handoff behavior | [Handoffs](/openai-agents-js/guides/handoffs) |
3940
| Run turns, stream events, or manage state | [Running agents](/openai-agents-js/guides/running-agents) |

docs/src/content/docs/guides/running-agents.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ The additional options are:
6969
| `toolErrorFormatter` || Hook to customize tool approval rejection messages returned to the model. See [Tool error formatter](#tool-error-formatter). |
7070
| `reasoningItemIdPolicy` || Controls whether reasoning-item `id`s are preserved or omitted when prior run items are turned back into model input. See [Reasoning item ID policy](#reasoning-item-id-policy). |
7171
| `tracing` || Per-run tracing configuration overrides (for example, export API key). |
72+
| `sandbox` || Sandbox client, live session, session state, snapshot, manifest override, or concurrency limits for `SandboxAgent` runs. See [Sandbox agents](/openai-agents-js/guides/sandbox-agents/concepts). |
7273
| `errorHandlers` || Handlers for supported runtime errors (currently `maxTurns`). See [Error handlers](#error-handlers). |
7374
| `conversationId` || Reuse a server-side conversation (OpenAI Responses API + Conversations API only). |
7475
| `previousResponseId` || Continue from the previous Responses API call without creating a conversation (OpenAI Responses API only). |
@@ -99,6 +100,7 @@ If you are creating your own `Runner` instance, you can pass in a `RunConfig` ob
99100
| `callModelInputFilter` | `CallModelInputFilter` | Global hook to edit model inputs before each model call. |
100101
| `toolErrorFormatter` | `ToolErrorFormatter` | Global hook to customize tool approval rejection messages returned to the model. |
101102
| `reasoningItemIdPolicy` | `ReasoningItemIdPolicy` | Default policy for preserving or omitting reasoning-item `id`s when replaying generated items into later model calls. |
103+
| `sandbox` | `SandboxRunConfig` | Default sandbox runtime configuration for `SandboxAgent` runs. |
102104

103105
## State and conversation management
104106

@@ -115,6 +117,8 @@ There are four common ways to carry state into the next turn:
115117

116118
`result.history` and `session` are client-managed. `conversationId` and `previousResponseId` are OpenAI-managed and only apply when you are using the OpenAI Responses API. In most applications, pick one persistence strategy per conversation. Mixing client-managed history with server-managed state can duplicate context unless you are deliberately reconciling both layers.
117119

120+
Sandbox agents add another state layer: the live sandbox workspace. Use the regular SDK `session`, `conversationId`, or `previousResponseId` for conversation history, and use `sandbox.session`, `sandbox.sessionState`, `RunState`, or snapshots for sandbox filesystem state. See [Sandbox agents](/openai-agents-js/guides/sandbox-agents/concepts) for the workspace lifecycle.
121+
118122
### Conversations / chat threads
119123

120124
Each call to `runner.run()` (or `run()` utility) represents one **turn** in your application-level conversation. You choose how much of the `RunResult` you show the end‑user – sometimes only `finalOutput`, other times every generated item.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
---
2+
title: Quickstart
3+
description: Create your first sandbox agent with an isolated workspace, filesystem tools, shell commands, and sandbox session state.
4+
---
5+
6+
import { Aside, Code } from '@astrojs/starlight/components';
7+
import basicExample from '../../../../../examples/docs/sandbox-agents/basic.ts?raw';
8+
9+
<Aside type="caution" title="Beta feature">
10+
Sandbox agents are in beta. API details, defaults, and supported capabilities
11+
may change before general availability, and more advanced features are
12+
expected over time.
13+
</Aside>
14+
15+
Modern agents work best when they can operate on real files in a filesystem. **Sandbox Agents** in the Agents SDK give the model a persistent workspace where it can search large document sets, edit files, run commands, generate artifacts, and pick work back up from saved sandbox state.
16+
17+
The SDK gives you that execution harness without making you wire together file staging, filesystem tools, shell access, sandbox lifecycle, snapshots, and provider-specific glue yourself. You keep the normal `Agent` and `Runner` flow, then add a `Manifest` for the workspace, capabilities for sandbox-native tools, and the `sandbox` run option for where the work runs.
18+
19+
## Prerequisites
20+
21+
- Node.js 22 or higher.
22+
- Basic familiarity with the OpenAI Agents SDK.
23+
- A sandbox client. For local development, start with `UnixLocalSandboxClient`.
24+
25+
## Installation
26+
27+
If you have not already installed the SDK:
28+
29+
```bash
30+
npm install @openai/agents
31+
```
32+
33+
For Docker-backed sandboxes, install Docker locally and use `DockerSandboxClient` from `@openai/agents/sandbox/local`.
34+
35+
If you use interactive local PTY sessions with `tty: true`, the process running the SDK also needs Python 3 available as `python3`, or through `OPENAI_AGENTS_PYTHON`. Non-PTY shell commands do not require Python.
36+
37+
## Create a local sandbox agent
38+
39+
This example stages a local repo under `repo/`, loads local skills lazily, and lets the runner create a Unix-local sandbox session for the run.
40+
41+
<Code
42+
lang="typescript"
43+
code={basicExample}
44+
title="Create a local sandbox agent"
45+
/>
46+
47+
The example is intentionally shaped like the Python SDK quickstart: the agent definition owns the manifest and capabilities, while the run config only chooses the sandbox client for this run.
48+
49+
## Key choices
50+
51+
Once the basic run works, the choices most people reach for next are:
52+
53+
- `defaultManifest`: the files, repos, directories, and mounts for fresh sandbox sessions.
54+
- `instructions`: short workflow rules that should apply across prompts.
55+
- `baseInstructions`: an advanced escape hatch for replacing the SDK sandbox prompt.
56+
- `capabilities`: sandbox-native tools such as filesystem editing/image inspection, shell, skills, memory, and compaction.
57+
- `runAs`: the sandbox user identity for model-facing tools.
58+
- `sandbox.client`: the sandbox backend.
59+
- `sandbox.session`, `sandbox.sessionState`, or `sandbox.snapshot`: how later runs reconnect to prior work.
60+
61+
## Where to go next
62+
63+
- [Concepts](/openai-agents-js/guides/sandbox-agents/concepts): understand manifests, capabilities, permissions, snapshots, run config, and composition patterns.
64+
- [Sandbox clients](/openai-agents-js/guides/sandbox-agents/clients): choose Unix-local, Docker, hosted providers, and mount strategies.
65+
- [Agent memory](/openai-agents-js/guides/sandbox-agents/memory): preserve and reuse lessons from previous sandbox runs.
66+
67+
If shell access is only one occasional tool, start with hosted shell in the [Tools guide](/openai-agents-js/guides/tools). Reach for sandbox agents when workspace isolation, sandbox client choice, or sandbox-session resume behavior are part of the design.

0 commit comments

Comments
 (0)