Sandbox0 Python SDK
Project description
Sandbox0 Python SDK
The official Python SDK for Sandbox0, providing typed models and ergonomic high-level APIs for managing secure code execution sandboxes.
Installation
pip install sandbox0
Requirements
- Python 3.9 or later
Configuration
| Environment Variable | Required | Default | Description |
|---|---|---|---|
SANDBOX0_TOKEN |
Yes | - | API authentication token |
SANDBOX0_BASE_URL |
No | https://api.sandbox0.ai |
API base URL |
Quick Start
import os
from sandbox0 import Client, CmdOptions
client = Client(token=os.environ["SANDBOX0_TOKEN"])
# Using context manager for automatic cleanup
with client.sandboxes.open("default") as sandbox:
# Execute Python code (REPL - stateful)
result = sandbox.run("python", "print('Hello, Sandbox0!')")
print(result.output_raw, end="")
CMD Streaming
stream = sandbox.cmd_stream(
"sh -c 'echo hello && echo warn >&2'",
CmdOptions(command=["sh", "-c", "echo hello && echo warn >&2"]),
)
for output in stream.iter_outputs():
print(output.data, end="")
done = stream.wait()
print(f"exit={done.exit_code} state={done.state}")
OpenAI Agents SDK Sandbox
Install the optional adapter dependency:
pip install "sandbox0[openai-agents]"
Use Sandbox0SandboxClient anywhere the OpenAI Agents SDK expects a sandbox client:
import os
from agents import Runner
from agents.run_config import RunConfig, SandboxRunConfig
from agents.sandbox import SandboxAgent
from sandbox0_openai_agents import Sandbox0SandboxClient, Sandbox0SandboxClientOptions
client = Sandbox0SandboxClient(
token=os.environ["SANDBOX0_TOKEN"],
base_url=os.environ.get("SANDBOX0_BASE_URL"),
)
sandbox_agent = SandboxAgent(
name="demo",
instructions="Use the sandbox for filesystem and command execution tasks.",
)
result = Runner.run_sync(
sandbox_agent,
"Create hello.txt in the sandbox, then print it.",
run_config=RunConfig(
sandbox=SandboxRunConfig(
client=client,
options=Sandbox0SandboxClientOptions(template="default"),
),
),
)
print(result.final_output)
The adapter keeps the OpenAI SDK workspace at /workspace on a Sandbox0
SandboxVolume. delete() releases the sandbox runtime and deletes the
workspace volume by default. Set delete_volume_on_delete=False when serialized
session state must resume the same workspace volume after cleanup. Use
Sandbox0SandboxClientOptions(volume_snapshot_id="...") for Sandbox0-native
volume snapshots; generic OpenAI SDK snapshot specs are not used by this
adapter.
Documentation
Bootstrap Mounts At Claim Time
from sandbox0.apispec.models.claim_mount_request import ClaimMountRequest
from sandbox0.apispec.models.create_sandbox_volume_request import CreateSandboxVolumeRequest
volume = client.volumes.create(CreateSandboxVolumeRequest())
sandbox = client.sandboxes.claim(
"default",
mounts=[
ClaimMountRequest(
sandboxvolume_id=volume.id,
mount_point="/workspace/data",
)
],
)
for mount in sandbox.bootstrap_mounts:
print(mount.sandboxvolume_id, mount.state)
Links
License
Apache-2.0
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sandbox0-0.7.3.tar.gz.
File metadata
- Download URL: sandbox0-0.7.3.tar.gz
- Upload date:
- Size: 156.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6f831a1c3c5e6b2b4e9b19b3a474e92cb06cd9c8ac828e98a1bdd9f38232b0e9
|
|
| MD5 |
95d5bbbc6cdbeeb0b6584343b935b894
|
|
| BLAKE2b-256 |
fb9b543f00b3153528e1541f16718bac78c755075b004907d1082f3337c63b46
|
File details
Details for the file sandbox0-0.7.3-py3-none-any.whl.
File metadata
- Download URL: sandbox0-0.7.3-py3-none-any.whl
- Upload date:
- Size: 476.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4dda333f52b28d29807b88d3f9b3982ad7d0a6927afac8e43da766cd38ad45fe
|
|
| MD5 |
712b6706318399a6d0be1f75b025fb5f
|
|
| BLAKE2b-256 |
84c28c467ad1e94f256adb118daef26e8dc6e80583a015253923508a96f94172
|