2d665c9a67
### Sandbox Agents This release adds **Sandbox Agents**, a beta SDK surface for running agents with a persistent, isolated workspace. Sandbox agents keep the normal `Agent` and `Runner` flow, but add workspace manifests, sandbox-native capabilities, sandbox clients, snapshots, and resume support so agents can work over real files, run commands, edit repositories, generate artifacts, and continue work across runs. Key pieces: - `SandboxAgent`: an `Agent` with sandbox defaults such as `default_manifest`, sandbox instructions, capabilities, and `run_as`. - `Manifest`: a fresh-workspace contract for files, directories, local files, local directories, Git repos, environment, users, groups, and mounts. - `SandboxRunConfig`: per-run sandbox wiring for client creation, live session injection, serialized session resume, manifest overrides, snapshots, and materialization concurrency limits. - Built-in capabilities for shell access, filesystem editing and image inspection, skills, memory, and compaction. - Workspace snapshots and serialized sandbox session state for reconnecting to existing work or seeding a fresh sandbox from saved contents. ### Sandbox clients and hosted providers Sandbox agents now support local, containerized, and hosted execution backends: - `UnixLocalSandboxClient` for fast local development. - `DockerSandboxClient` for container isolation and image parity. - Hosted sandbox clients for Blaxel, Cloudflare, Daytona, E2B, Modal, Runloop, and Vercel through optional extras. The release also adds provider-specific examples and mount strategies for common storage backends, including S3, Cloudflare R2, Google Cloud Storage, Azure Blob Storage, and S3 Files where supported by the selected backend. ### Sandbox memory Adds a sandbox memory capability that lets future sandbox-agent runs learn from prior runs. Memory stores extracted lessons in the sandbox workspace, injects a concise summary into later runs, and uses progressive disclosure so agents can search deeper rollout summaries only when useful. Memory supports: - Read-only or generate-only modes. - Live updates when the agent discovers stale memory. - Multi-turn grouping through `conversation_id`, SDK `Session`, `RunConfig.group_id`, or generated run IDs. - Separate memory layouts for isolating memory across agents or workflows. - S3-backed examples for persisted memory across runs. ### Workspace mounts, snapshots, and resume This release adds a full workspace entry and mount model for sandbox sessions: - Local files and directories. - Synthetic files and directories. - Git repository entries. - Remote storage mounts for S3, R2, GCS, Azure Blob Storage, and S3 Files. - Provider-specific mount strategies across Docker, Modal, Cloudflare, Blaxel, Daytona, E2B, and Runloop. - Portable snapshots with path normalization, symlink preservation, mount-safe snapshotting, and remote snapshot support. - Resume paths through runner-managed `RunState`, explicit `SandboxSessionState`, or saved snapshots. ### Examples and tutorials Adds a large `examples/sandbox/` suite covering: - Local Unix and Docker sandbox runners. - Docker mount smoke tests for S3, GCS, Azure Blob Storage, and S3 Files. - Sandbox coding tasks with skills. - Sandbox agents as tools and handoff patterns. - Memory examples, including multi-agent/multi-turn memory and S3-backed memory. - Tax-prep and healthcare-support workflows. - Dataroom QA and metric extraction tutorials. - Repository code review tutorial. - Vision website clone tutorial. - Provider examples for Blaxel, Cloudflare, Daytona, E2B, Modal, Runloop, Temporal, and Vercel. ### Runtime, tracing, and model plumbing The release includes the runtime plumbing needed to make sandbox agents work naturally inside the existing SDK: - Runner-managed sandbox preparation, capability binding, session lifecycle, state serialization, and resume behavior. - Sandbox-aware `RunState` serialization. - Unified sandbox tracing with SDK spans. - Token usage on tracing spans. - Runner-managed prompt cache key defaults. - OpenAI agent registration and harness ID configuration. - Safer redaction of sensitive MCP tool outputs when sensitive tracing is disabled. - Additional OpenAI client/model utilities and Chat Completions coverage. ## Documentation & Other Changes - docs: add Asqav to external tracing processors list. - docs: update translated document pages. Co-authored-by: Abdulrahman Alfozan <alfozan@openai.com> Co-authored-by: Aditya Singh <60082699+adityasingh2400@users.noreply.github.com> Co-authored-by: Andi Liu <andi@openai.com> Co-authored-by: Aron <263346377+aron-cf@users.noreply.github.com> Co-authored-by: ashwinnathan-openai <ashwinnathan@openai.com> Co-authored-by: Codex <noreply@openai.com> Co-authored-by: cploujoux <cploujoux@blaxel.ai> Co-authored-by: elainegan-openai <168589666+elainegan-openai@users.noreply.github.com> Co-authored-by: Elias Freider <freider@users.noreply.github.com> Co-authored-by: Erik Dunteman <erik@erikds-macbook-air.local> Co-authored-by: Jason Liu <jasonliu@openai.com> Co-authored-by: Jason Steving <32336750+jasonsteving99@users.noreply.github.com> Co-authored-by: Kazuhiro Sera <seratch@openai.com> Co-authored-by: Lovre Pešut <lovre.pesut@gmail.com> Co-authored-by: Lucas Wang <lucas_wang@lucas-futures.com> Co-authored-by: Matt Brockman <matt.brockman@e2b.dev> Co-authored-by: Mish Ushakov <mishushakov@users.noreply.github.com> Co-authored-by: Naresh <ghostwriternr@gmail.com> Co-authored-by: nicholasclark-openai <nicholasclark@openai.com> Co-authored-by: qiyaoq-oai <qiyaoq@openai.com> Co-authored-by: Scott Trinh <scott@scotttrinh.com> Co-authored-by: tode-rl <tony@runloop.ai> Co-authored-by: Wendy Jiao <wendyjiao@openai.com>
154 lines
4.6 KiB
Python
154 lines
4.6 KiB
Python
from __future__ import annotations
|
|
|
|
import os
|
|
import uuid
|
|
from collections.abc import Sequence
|
|
from dataclasses import dataclass
|
|
from pathlib import Path
|
|
|
|
import docker # type: ignore[import-untyped]
|
|
|
|
from agents import ModelSettings, Runner
|
|
from agents.run import RunConfig
|
|
from agents.sandbox import Manifest, SandboxAgent, SandboxRunConfig
|
|
from agents.sandbox.entries import Mount
|
|
from agents.sandbox.errors import MountCommandError
|
|
from agents.sandbox.sandboxes.docker import (
|
|
DockerSandboxClient,
|
|
DockerSandboxClientOptions,
|
|
)
|
|
from agents.sandbox.session.sandbox_session import SandboxSession
|
|
from examples.sandbox.misc.workspace_shell import WorkspaceShellCapability
|
|
|
|
IMAGE = "agents-sandbox-docker-mount-example:latest"
|
|
DOCKERFILE = Path(__file__).resolve().parent.parent / "Dockerfile.mount"
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class MountSmokeCase:
|
|
"""One mount target to verify inside a shared Docker sandbox session."""
|
|
|
|
name: str
|
|
mount_dir: str
|
|
mount: Mount
|
|
|
|
|
|
def require_env(name: str) -> str:
|
|
"""Return a required environment variable or stop with a clear message."""
|
|
|
|
value = os.getenv(name)
|
|
if not value:
|
|
raise SystemExit(f"Missing required environment variable: {name}")
|
|
return value
|
|
|
|
|
|
def ensure_mount_image() -> None:
|
|
"""Build the Docker image with the in-container mount CLIs if it is missing."""
|
|
|
|
docker_client = docker.from_env()
|
|
try:
|
|
docker_client.images.get(IMAGE)
|
|
return
|
|
except docker.errors.ImageNotFound:
|
|
pass
|
|
|
|
print(f"building {IMAGE} from {DOCKERFILE.name}...")
|
|
docker_client.images.build(
|
|
path=str(DOCKERFILE.parent),
|
|
dockerfile=DOCKERFILE.name,
|
|
tag=IMAGE,
|
|
rm=True,
|
|
)
|
|
|
|
|
|
def build_agent(name: str, manifest: Manifest) -> SandboxAgent:
|
|
"""Create the minimal shell-only agent used by these mount smoke tests."""
|
|
|
|
return SandboxAgent(
|
|
name=name,
|
|
model=os.getenv("OPENAI_MODEL", "gpt-5.4"),
|
|
instructions=(
|
|
"Use the shell tool only. Write the requested exact content to the requested exact "
|
|
"path, read the file back with cat, and then reply with only `done`."
|
|
),
|
|
default_manifest=manifest,
|
|
capabilities=[WorkspaceShellCapability()],
|
|
model_settings=ModelSettings(tool_choice="required"),
|
|
)
|
|
|
|
|
|
async def _check_case(
|
|
sandbox: SandboxSession,
|
|
agent: SandboxAgent,
|
|
provider: str,
|
|
mount_case: MountSmokeCase,
|
|
) -> None:
|
|
key = f"docker-{provider}-mount-example-{mount_case.mount_dir}-{uuid.uuid4().hex}.txt"
|
|
path = Path("/workspace") / mount_case.mount_dir / key
|
|
expected = f"hello from {mount_case.name} {uuid.uuid4().hex}"
|
|
|
|
result = await Runner.run(
|
|
agent,
|
|
(
|
|
f"Write exactly this content to {path} with `printf %s`, not `echo`: {expected}\n"
|
|
f"Then read {path} back with cat."
|
|
),
|
|
run_config=RunConfig(
|
|
sandbox=SandboxRunConfig(session=sandbox),
|
|
workflow_name=f"Docker {provider} mount smoke test ({mount_case.name})",
|
|
),
|
|
)
|
|
print(result.final_output)
|
|
|
|
read_back = await sandbox.read(path)
|
|
actual = read_back.read()
|
|
if not isinstance(actual, bytes):
|
|
raise TypeError(f"Expected bytes from session.read(), got {type(actual)!r}")
|
|
|
|
actual_text = actual.decode("utf-8")
|
|
if actual_text == f"{expected}\n":
|
|
actual_text = expected
|
|
|
|
assert actual_text == expected, f"read back {actual!r}, expected {expected!r}"
|
|
print(f"{mount_case.name}: ok")
|
|
|
|
|
|
async def run_mount_smoke_test(
|
|
*,
|
|
provider: str,
|
|
agent_name: str,
|
|
mount_cases: Sequence[MountSmokeCase],
|
|
) -> None:
|
|
"""Start one Docker sandbox session and verify read/write on every mount target."""
|
|
|
|
ensure_mount_image()
|
|
|
|
manifest = Manifest(
|
|
entries={mount_case.mount_dir: mount_case.mount for mount_case in mount_cases},
|
|
)
|
|
agent = build_agent(agent_name, manifest)
|
|
client = DockerSandboxClient(docker.from_env())
|
|
|
|
try:
|
|
sandbox = await client.create(
|
|
manifest=manifest,
|
|
options=DockerSandboxClientOptions(image=IMAGE),
|
|
)
|
|
except docker.errors.NotFound as exc:
|
|
if 'plugin "rclone" not found' in str(exc):
|
|
raise SystemExit("rclone Docker volume plugin not found") from exc
|
|
raise
|
|
|
|
try:
|
|
await sandbox.start()
|
|
except MountCommandError as exc:
|
|
print(f"mount command: {exc.context.get('command')}")
|
|
print(f"mount stderr: {exc.context.get('stderr')}")
|
|
raise
|
|
|
|
try:
|
|
for mount_case in mount_cases:
|
|
await _check_case(sandbox, agent, provider, mount_case)
|
|
finally:
|
|
await client.delete(sandbox)
|