OpenSandbox
Run your agent’s commands and file edits in a sandbox on your own OpenSandbox server, created on first use. The server runs sandboxes as Docker containers on one machine or as pods on Kubernetes; the agent’s code is the same either way.
While Pydantic AI Harness is on 0.x releases, the API may change between minor releases; when it does, deprecation warnings and release-note migration guidance tell you (or your agent) exactly how to upgrade. See the version policy.
pip install "pydantic-ai-harness[coder,opensandbox,anthropic]"
uv add "pydantic-ai-harness[coder,opensandbox,anthropic]"
The opensandbox extra installs the OpenSandbox SDK. The examples also use Coder and an Anthropic model, hence the coder and anthropic extras and ANTHROPIC_API_KEY; swap them for your own tools and model provider.
The capability talks to an OpenSandbox server. To run one on this machine with Docker:
uvx opensandbox-server init-config ~/.sandbox.toml --example docker
uvx opensandbox-server
Then set execd_image = "opensandbox/execd:release-1.2.0" under [runtime] in ~/.sandbox.toml. execd runs the commands inside each sandbox, and the capability needs version 1.1.1 or later. With an older one, the first operation raises WorkspaceUnavailableError.
The capability reads two environment variables:
OPEN_SANDBOX_DOMAIN, the server’s address. Default:localhost:8080. Requests use plain HTTP unless it starts withhttps://, such ashttps://sandbox.example.com.OPEN_SANDBOX_API_KEY, sent if your server requires a key.
For Kubernetes, see Run on Kubernetes.
from pydantic_ai import Agent
from pydantic_ai_harness.coder import Coder
from pydantic_ai_harness.opensandbox_sandbox import OpenSandbox
agent = Agent('anthropic:claude-opus-5-5', capabilities=[OpenSandbox(image='python:3.13-slim'), Coder()])
result = agent.run_sync('Write a script that prints the first 10 primes, and run it.')
Coder’s shell and file tools now run in the sandbox. For a narrower agent, use Shell, FileSystem or your own tools on ctx.workspace.
Codercreates it when the run starts, to load the repository’s instructions, even if no tool is called. PassCoder(repo_context=False)to wait for the first tool call.- It keeps running after the run until you destroy it. If you set
sandbox_timeout, the server also deletes it after that many seconds unused. See Clean up. - Commands run as the image’s user, usually
root, in/workspace, which is created if missing. The image needs a POSIXshand the usual file utilities. - Its network access is whatever the server configures. Pass
allow_internet_access=Falseto block all outbound connections. See Network access.
Pass the message history, and the next run works in the same sandbox:
from pydantic_ai import Agent
from pydantic_ai_harness.coder import Coder
from pydantic_ai_harness.opensandbox_sandbox import OpenSandbox
agent = Agent('anthropic:claude-opus-5-5', capabilities=[OpenSandbox(image='python:3.13-slim'), Coder()])
result = agent.run_sync('Write a script that prints the first 10 primes, and run it.')
followup = agent.run_sync('Now make it print the first 100.', message_history=result.all_messages())
ref = result.workspace.ref # or store this, and pass `workspace=ref` to a later run
result.workspace.ref is a WorkspaceRef holding the sandbox’s id. Store it to continue later or to destroy the sandbox.
If the sandbox has been destroyed, the run raises WorkspaceUnavailableError. Pass workspace='new' to start over. Workspaces covers how runs find their workspace.
Whoever passes a ref runs commands in that sandbox, and the server serves every sandbox to every holder of its API key. Only pass refs your application stored itself.
To seed files or install packages before the agent starts, create the backend yourself, work in it through Workspace, and pass it to the run:
import asyncio
from pydantic_ai import Agent
from pydantic_ai.workspaces import Workspace
from pydantic_ai_harness.coder import Coder
from pydantic_ai_harness.opensandbox_sandbox import OpenSandbox, OpenSandboxBackend
agent = Agent('anthropic:claude-opus-5-5', capabilities=[OpenSandbox(image='python:3.13-slim'), Coder()])
async def main() -> None:
backend = OpenSandboxBackend(image='python:3.13-slim')
try:
workspace = Workspace(backend)
await workspace.write_text('calc.py', 'def add(a, b):\n return a - b\n')
install = await workspace.run(['pip', 'install', 'pytest'], timeout=300)
if install.exit_code != 0:
raise RuntimeError(f'pip install failed: {install.stderr}')
result = await agent.run('Fix the bug in calc.py.', workspace=backend)
print(result.output)
finally:
await backend.aclose()
if backend.ref is not None:
await OpenSandbox().destroy(backend.ref)
if __name__ == '__main__':
asyncio.run(main())
The finally destroys the sandbox even when setup or the run fails. aclose() closes the backend’s connection to the server. To keep the sandbox, store backend.ref instead.
OpenSandbox’s settings don’t apply to a backend you pass as workspace=. Give the backend its own.
Pass desktop=True and add ComputerUse:
capabilities=[OpenSandbox(image='debian:bookworm-slim', desktop=True), ComputerUse()]. The screen is 1280x800;
pass a size such as desktop=(1440, 900) for another.
- When the image’s user is root, the first use installs the display’s programs that are missing with
apt-get, which needs the sandbox to reach the package repositories. Passwordlesssudoworks only where the server allows it: the Docker runtime’s defaultno_new_privileges = trueblocks it. Otherwise build them into the image: without the screen’s programs the first use raisesWorkspaceUnavailableErrornaming what is missing, and without the desktop’s the screen works but stays black. - On the Docker runtime, set
network_mode = "bridge"under[docker]in the server’s configuration; see Security model. - Use execd 1.2 or later: on older versions every screen action is slow.
- There’s no web browser. Install one in the image or before the run, as in Prepare a sandbox before the run with
OpenSandboxBackend(..., desktop=True), or let the agent install it withShell. - The agent can type only ASCII: an action that types or presses a character such as
éfails, and the model is told why.
Destroy a sandbox, files included, with the ref you stored. A sandbox that is already gone returns quietly:
from pydantic_ai.workspaces import WorkspaceRef
from pydantic_ai_harness.opensandbox_sandbox import OpenSandbox
async def remove_sandbox(ref: WorkspaceRef) -> None:
await OpenSandbox().destroy(ref)
OpenSandbox() without an image only attaches to and destroys sandboxes by ref.
A failed run returns no result, so destroy its sandbox in an on_run_error hook:
from typing import Any
import anyio
from pydantic_ai import Agent, RunContext
from pydantic_ai.capabilities import Hooks
from pydantic_ai.run import AgentRunResult
from pydantic_ai_harness.coder import Coder
from pydantic_ai_harness.opensandbox_sandbox import OpenSandbox
hooks = Hooks()
@hooks.on.run_error
async def destroy_failed_run_sandbox(ctx: RunContext[None], *, error: BaseException) -> AgentRunResult[Any]:
if ctx.workspace.ref is not None:
# Shielded so a deadline around the run can't cut the destroy short, bounded so a hung call can't hang it.
with anyio.move_on_after(30, shield=True):
await OpenSandbox().destroy(ctx.workspace.ref)
raise error
agent = Agent('anthropic:claude-opus-5-5', capabilities=[OpenSandbox(image='python:3.13-slim'), Coder(), hooks])
To have the server clean up for you, set sandbox_timeout. The server deletes a sandbox unused for that many seconds, files included. Every operation restarts the countdown, but a single command must finish within it, so set it above your longest command.
If your program stops before it stores the ref, for example after a crash or Ctrl-C, the sandbox is left on the server. To find it:
- List the server’s sandboxes. Sandboxes Pydantic AI creates have a
pydantic-ai-createmetadata entry. - Or search your logs for
Created OpenSandbox sandbox <id>, logged at INFO by thepydantic_ai_harnesslogger.
Then destroy it: await OpenSandbox().destroy(WorkspaceRef(provider='opensandbox', id='<id>')).
On a server deployed with OpenSandbox’s Helm charts, sandboxes are pods. The server creates them through OpenSandbox’s own BatchSandbox resources or through agent-sandbox, and both work the same here.
Pods are reachable only inside the cluster. Either deploy the server’s ingress gateway, or let the server proxy commands with use_server_proxy=True:
from opensandbox.config import ConnectionConfig
from pydantic_ai_harness.opensandbox_sandbox import OpenSandbox
sandbox = OpenSandbox(
image='python:3.13-slim',
connection=ConnectionConfig(domain='opensandbox.internal:8080', use_server_proxy=True),
resource={'cpu': '500m', 'memory': '1Gi'},
)
This connects over plain HTTP inside the cluster. For HTTPS, put the server behind TLS and pass ConnectionConfig(domain='https://opensandbox.example.com', protocol='https', use_server_proxy=True). The SDK uses the domain’s scheme for the server’s API and protocol for command and file requests, so a config needs both.
Each sandbox asks for one CPU and 2 GiB unless you pass resource. If its pod can’t be scheduled within 30 seconds, the create times out, but the server may still finish it. The next operation then attaches to that sandbox instead of creating another.
allow_internet_access=False asks the server to create the sandbox with a policy that blocks all outbound connections. The default, True, sends no policy, so the server’s own configuration applies. Attaching never changes a sandbox’s policy.
The server enforces the policy with its egress sidecar, a container next to the sandbox. In the default dns mode it filters DNS lookups only, so a command can still connect to an IP address directly. To block both, configure the server with:
[egress]
image = "opensandbox/egress:v1.1.7"
mode = "dns+nft"
OpenSandbox egress configuration covers runtime requirements and server-level allow and deny rules.
OpenSandbox’s Credential Vault holds a token outside the sandbox and adds it to the sandbox’s outgoing requests to the hosts you name, so the token is never inside the sandbox.
Turn it on by passing credential_proxy and network_policy to OpenSandboxBackend. Both take the SDK’s own objects and pass them on unchanged. In an image with git and gh, both then work as the token’s owner, while echo $GH_TOKEN in the sandbox prints placeholder:
import base64
from opensandbox.models.sandboxes import (
Credential,
CredentialAuth,
CredentialBinding,
CredentialMatch,
CredentialProxyConfig,
InlineCredentialSource,
NetworkPolicy,
NetworkRule,
)
from pydantic_ai_harness.opensandbox_sandbox import OpenSandboxBackend
token = '...' # a GitHub token, such as the output of `gh auth token`
basic = base64.b64encode(f'x-access-token:{token}'.encode()).decode()
hosts = ['github.com', 'api.github.com', 'uploads.github.com']
async def github_sandbox() -> OpenSandboxBackend:
backend = OpenSandboxBackend(
image='python:3.13-slim',
env={'GH_TOKEN': 'placeholder'}, # `gh` sends a token only when one is set; the vault replaces it
network_policy=NetworkPolicy(
defaultAction='deny', egress=[NetworkRule(action='allow', target=host) for host in hosts]
),
credential_proxy=CredentialProxyConfig(enabled=True),
)
sandbox = await backend.get_sandbox()
await sandbox.credential_vault.create(
credentials=[
Credential(name='github-basic', source=InlineCredentialSource(value=basic)),
Credential(name='github-token', source=InlineCredentialSource(value=token)),
],
bindings=[
CredentialBinding( # git over HTTPS
name='git',
match=CredentialMatch(hosts=['github.com']),
auth=CredentialAuth(type='basic', credential='github-basic'),
),
CredentialBinding( # gh, including release uploads
name='gh',
match=CredentialMatch(hosts=['api.github.com', 'uploads.github.com']),
auth=CredentialAuth(type='bearer', credential='github-token'),
),
],
)
return backend
Pass the backend as workspace=, as in Prepare a sandbox before the run. credential_proxy is on OpenSandboxBackend only, because the vault has to be filled after the sandbox exists and before the agent’s first command.
Before you rely on it:
- The server must filter traffic in
dns+nftmode (see Network access), or creating the sandbox fails. - The policy must allow every host in the vault, and any other host the agent needs, such as a package index.
- Only HTTPS requests get the token, replacing any
Authorizationheader they carried. Usehttps://remotes, notgit@github.com:owner/repo.git. - The agent can’t see the token, but it can use it for anything the token allows.
- The vault doesn’t hide the token in responses. List only hosts that never send request headers back, or a command could read the token there.
- The vault is kept in memory next to the sandbox. Pausing and resuming a Kubernetes sandbox, or restarting the server’s network proxy, empties it, so fill it again after you reattach.
- To swap the token, call
credential_vault.patch(credentials={'replace': [...]})onawait backend.get_sandbox(). allow_internet_access=Falsealready sets a policy that blocks everything, so pass it ornetwork_policy, not both. For both,OpenSandboxraisesUserErrorandOpenSandboxBackendraisesValueError.
secure_access=True asks the server to turn on Secure Access for a new sandbox. The gateway and the server proxy then reject requests to the sandbox’s endpoints that lack its token. The SDK fetches the token with the server API key and sends it with every command and file request.
- It needs Kubernetes with the server’s ingress gateway:
[ingress]withmode = "gateway". Docker rejects it. - Requests that reach the pod without passing through the gateway or proxy, such as from elsewhere in the cluster, are not checked.
The sandbox is as isolated as the server’s runtime makes it. A Docker container shares the host’s kernel, and a Kubernetes pod shares its node’s, unless the server is configured with a secure runtime such as gVisor or Kata Containers. Commands run as the image’s user, usually root.
- With the default
allow_internet_access=True, a Docker-backed sandbox can reach its host and LAN, including the OpenSandbox server if it listens there.Falseon a server indns+nftmode blocks that. - Requests to the server’s API carry the server API key. Command and file requests carry commands, file contents and
envvalues. Over plainhttp, all of them are unencrypted. AConnectionConfigyou pass is used as given, so set both anhttps://domain andprotocol='https'on it. - The server API key, set as
api_keyunder[server], controls every sandbox on that server and can fetch their Secure Access tokens. Keep it out of the sandbox’senv. - Without the server proxy, command and file requests go straight to the sandbox’s endpoint, without the server API key. The endpoint checks only what the server configures for it, such as Secure Access. With
use_server_proxy=True, they go through the server, which checks the API key. - With
desktopon the Docker runtime, the defaultnetwork_mode = "host"puts every sandbox on the host’s network. The desktop doesn’t start if the host or another sandbox already runs a second X server (a program that draws a screen) on display:1. One that starts there later can take the agent’s clicks and screenshots instead of its own screen. Setnetwork_mode = "bridge"under[docker]in the server’s configuration to give each sandbox its own network. imageis pulled by tag; pin a digest, such aspython:3.13-slim@sha256:..., to get the same image every time.
Agent specs can set every option except connection and network_policy. A spec reaches the server through OPEN_SANDBOX_DOMAIN and OPEN_SANDBOX_API_KEY.
| Option | What it does |
|---|---|
image | Image for a new sandbox, such as 'python:3.13-slim'. Default: None, which only attaches to and destroys sandboxes by ref. |
connection | The SDK’s ConnectionConfig for your server. Default: None, which reads OPEN_SANDBOX_DOMAIN and OPEN_SANDBOX_API_KEY. A config you pass is used as given. |
resource | Resource limits for a new sandbox, such as {'cpu': '500m', 'memory': '1Gi'}. Default: None, one CPU and 2 GiB. |
allow_internet_access | Whether a new sandbox may connect out. Default: True, which sends no policy, so the server’s configuration applies. False asks the server to block all outbound connections. |
network_policy | The SDK’s NetworkPolicy for a new sandbox, passed to Sandbox.create unchanged. Default: None. Cannot be combined with allow_internet_access=False. A spec cannot set it. |
secure_access | Whether a new sandbox’s endpoints require a token at the server’s Kubernetes ingress gateway and proxy. Default: False. Docker rejects True. |
sandbox_timeout | Seconds a sandbox may go unused before the server deletes it, files included. Every operation restarts the countdown, and a single command must finish within it. Default: None, kept until destroyed. |
working_dir | Absolute directory commands start in and relative paths resolve against, created on first use if missing. Default: /workspace. None uses the image’s own. |
env | Environment variables every command gets. Default: None. Nothing from your machine’s environment reaches the sandbox. The agent’s commands can read these, so leave out secrets it shouldn’t see. |
desktop | Give the sandbox a graphical display for ComputerUse: True for 1280x800, or its (width, height). The first use installs the screen’s programs with apt-get when the image’s user is root; passwordless sudo works only where the server allows it. The size applies when the display first starts. Default: False. |
authority | Who wrote the sandbox’s files: 'none' for files nobody on your side wrote, such as a cloned third-party repository, or 'user' for the user’s own. Capabilities that put a file into the prompt give it no more authority than this. Default: 'operator', files you wrote. |
path_authority | An authority level for specific directories and files, overriding authority under them. The longest matching path wins. Paths are sandbox paths, relative to the working directory or absolute, and ~ isn’t expanded. Default: None. |
image, resource, allow_internet_access, network_policy and secure_access only shape a new sandbox. working_dir, env, sandbox_timeout, desktop, authority and path_authority also apply when you reattach.
- Each command takes about a fifth of a second. File operations run as commands, so a large file takes several seconds per MiB. Keep large data out of the workspace, or fetch it from inside the sandbox.
- Creating the sandbox, including pulling the image, isn’t bounded by a command’s
timeout. - On a timeout or cancellation, the command and the processes it started are stopped.
- The OpenSandbox SDK needs asyncio. Under Trio, the capability raises
UserError.
Add a durability capability next to OpenSandbox(image=...). Workspaces covers what changes. Then:
- Configure the same capability and server connection on every worker.
- Set
sandbox_timeoutabove the longest gap between workspace operations, including workflow waits and retries. Nothing restarts the countdown while the workflow is idle. - A retried attempt can create a second sandbox if the first attempt’s ref wasn’t recorded yet. To avoid that, create the sandbox and store its ref before starting the workflow, then pass that ref as
workspace=.
OpenSandbox emits no spans of its own. Core’s instrumentation records pydantic_ai.workspace.provider (opensandbox) and pydantic_ai.workspace.id on the agent run span, and each command or file operation runs inside its tool call’s span.
The OpenSandbox SDK reports how long each create took to your server’s /metrics/events. Set OPENSANDBOX_DISABLE_METRICS=1, or pass ConnectionConfig(disable_metrics=True), to turn that off.
Bases: AbstractCapability[AgentDepsT]
Supply an OpenSandbox sandbox as the run’s workspace, created on first use.
from pydantic_ai import Agent
from pydantic_ai_harness import Coder, OpenSandbox
agent = Agent('anthropic:claude-opus-5-5', capabilities=[OpenSandbox(image='python:3.13-slim'), Coder()])
With an image, a run with no reference creates a fresh sandbox on your OpenSandbox server, on whichever
runtime it uses (Docker or Kubernetes). Pass a WorkspaceRef to attach to a sandbox created earlier.
Ending a run does not delete the sandbox: remove it with
destroy,
or set sandbox_timeout. Commands run as the image’s user. Outbound network access follows the server’s
policy unless allow_internet_access=False or network_policy sets one for a new sandbox.
This capability supplies the workspace only. Compose it with capabilities that use it, such as Coder,
Shell, and FileSystem. See Workspaces for more.
The image for a new sandbox, such as 'python:3.13-slim'; it needs a POSIX sh and the usual file utilities.
Without one, the capability only attaches to and destroys sandboxes by ref, and leaves a run without a ref to the agent’s other workspace capabilities.
Type: str | None Default: None
The opensandbox.config.ConnectionConfig for your server. When None, each run reads
OPEN_SANDBOX_DOMAIN and OPEN_SANDBOX_API_KEY, and an https:// domain applies to command and file
requests too. A config you pass is used as given: set protocol='https' on it for an encrypted connection.
On Kubernetes without the ingress gateway, pass ConnectionConfig(use_server_proxy=True).
Type: ConnectionConfig | None Default: field(default=None, repr=False)
Resource limits for a new sandbox, such as {'cpu': '500m', 'memory': '1Gi'}; None keeps the SDK’s
default of one CPU and 2 GiB.
Type: Mapping[str, str] | None Default: None
Whether a new sandbox keeps the server’s network policy. False requests deny-all egress.
Requires the server’s egress sidecar; direct IP connections are blocked only in dns+nft mode, not the
default DNS-only mode. Does not change the policy of an attached sandbox. Leave it True when you pass
network_policy.
Type: bool Default: True
The SDK’s NetworkPolicy for a new sandbox, passed to Sandbox.create unchanged; a spec cannot set it.
Does not change the policy of an attached sandbox.
Type: NetworkPolicy | None Default: None
Ask the server to turn on Secure Access for a new sandbox.
The server’s ingress gateway and proxy then require the sandbox’s token on its endpoints; requests that reach
the pod directly are not checked. Requires Kubernetes with an ingress gateway; Docker rejects True. The SDK
fetches the token with the server API key and sends it automatically, including after attaching. Does not
change the setting of an attached sandbox.
Type: bool Default: False
Seconds a sandbox may go unused before the server deletes it, files included. Every operation renews it as it
starts, so a single command must finish within it. None keeps it until it is destroyed.
Type: int | None Default: None
Absolute directory commands start in and relative paths resolve against, created on first use if
missing; None uses the image’s own.
Type: str | None Default: '/workspace'
Environment variables every command gets, also in an attached sandbox; a command’s env is layered on
top. Nothing is read from the host.
Type: Mapping[str, str] | None Default: field(default=None, repr=False)
The authority of the sandbox’s files: 'none' for files nobody on the
application’s side wrote, such as a cloned third-party repository, and 'user' for the user’s own files.
Anything below 'operator' wraps the workspace in an AuthorityWorkspace.
Type: Authority Default: 'operator'
Levels for some directories and files, overriding authority for the paths under them; the longest matching
path wins. Paths are sandbox paths: relative ones resolve against the working directory, and ~ isn’t expanded.
See Workspace.authority_of.
Type: Mapping[str, Authority] | None Default: None
Give the sandbox a graphical display, for ComputerUse: True
for 1280x800, or its (width, height). The first use installs the display’s programs with apt-get when the
image’s user is root; passwordless sudo works only where the server allows it.
Type: bool | tuple[int, int] Default: False
@classmethod
def from_spec(
cls,
*,
id: str | None = None,
description: str | None = None,
image: str | None = None,
resource: Mapping[str, str] | None = None,
allow_internet_access: bool = True,
secure_access: bool = False,
sandbox_timeout: int | None = None,
working_dir: str | None = '/workspace',
env: Mapping[str, str] | None = None,
authority: Authority = 'operator',
path_authority: Mapping[str, Authority] | None = None,
desktop: bool | tuple[int, int] = False,
**kwargs: Any,
) -> OpenSandbox[Any]
Build from an agent spec using fields expressible in JSON.
An explicit signature keeps the SDK’s ConnectionConfig annotation from hiding the configuration
schema. Specs use the server connection from the environment; pass connection in Python instead.
OpenSandbox[Any]
def backend(ref: WorkspaceRef) -> OpenSandboxBackend
Construct a lazy backend for an existing sandbox.
OpenSandboxBackend
@async
def destroy(ref: WorkspaceRef) -> None
Delete a sandbox by ID, files included; one that no longer exists returns quietly.
def get_workspace(
ctx: RunContext[AgentDepsT],
*,
ref: WorkspaceRef | None,
) -> WorkspaceBackend | None
The backend for this run, in an AuthorityWorkspace when authority or path_authority asks for one.
WorkspaceBackend | None
Bases: WorkspaceBackend, SupportsCommands, SupportsDisplay
Run commands in an OpenSandbox sandbox, created on first use.
Built with image, the first operation creates a sandbox from it; built with ref, it attaches to that
sandbox and raises WorkspaceUnavailableError if it is
gone. The backend never kills the sandbox: call
OpenSandbox.destroy with its ref.
The image needs a POSIX sh and the usual file utilities. File operations run through that shell. The
OpenSandbox SDK runs on asyncio only, so under Trio every operation raises UserError.
The image for a new sandbox. Pass it or ref, not both.
ref : WorkspaceRef | None Default: None
A WorkspaceRef(provider='opensandbox', id=<sandbox id>) to attach to instead of creating one.
connection : ConnectionConfig | None Default: None
The opensandbox.config.ConnectionConfig for the server; None reads OPEN_SANDBOX_DOMAIN
and OPEN_SANDBOX_API_KEY. A transport you pass in it is yours to close.
Absolute directory commands start in and relative paths resolve against, created on first
use if missing; None uses the image’s own.
Environment variables every command gets; the per-call env goes on top. Nothing is read from the host.
Resource limits for a new sandbox, such as {'cpu': '500m', 'memory': '1Gi'}; None keeps the
SDK’s default of one CPU and 2 GiB.
allow_internet_access : bool Default: True
Whether a new sandbox keeps the server’s network policy. False requests deny-all
egress; blocking direct IP connections requires the server’s dns+nft egress mode. Ignored on attach.
Leave it True when you pass network_policy.
network_policy : NetworkPolicy | None Default: None
The SDK’s NetworkPolicy for a new sandbox, passed to Sandbox.create unchanged.
Ignored on attach.
credential_proxy : CredentialProxyConfig | None Default: None
The SDK’s CredentialProxyConfig for a new sandbox, passed to Sandbox.create
unchanged. CredentialProxyConfig(enabled=True) has the server add the tokens in the sandbox’s
credential_vault to matching requests as they leave the sandbox. Ignored on attach.
secure_access : bool Default: False
Ask the server to turn on Secure Access for a new sandbox, so its ingress gateway and
proxy require the sandbox’s token. Requires Kubernetes with an ingress gateway; Docker rejects True.
Ignored on attach.
Seconds a sandbox may go unused before the server deletes it, files included. Every
operation renews it as it starts, so a single command must finish within it. None keeps it until it
is destroyed.
Whether the sandbox has a display for
ComputerUse: True for 1280x800, or its
(width, height). The first use installs the programs it needs with apt-get when the image’s user is
root; passwordless sudo works only where the server allows it. No port or endpoint is opened for it.
The sandbox’s desktop, when created with desktop=True.
Type: Display | None
WorkspaceRef(provider='opensandbox', id=<sandbox id>), or None before a sandbox has been created.
Type: WorkspaceRef | None
@async
def get_sandbox() -> Sandbox
The opensandbox.Sandbox, for features the workspace API does not cover.
On a backend with no sandbox yet this creates one, or attaches to the one ref names, just like the
first operation. It shares the backend’s transport, so it stops working once the backend closes: at
aclose(), and, for a backend OpenSandbox built that no run owns, after each operation.
Sandbox
@async
def aclose() -> None
Close the HTTP transport the SDK opened; the sandbox keeps running.
The transport belongs to the event loop that opened it, so a backend used from another loop must be
closed first; a later operation attaches again by ref. An operation in flight keeps it open until the
last one ends. OpenSandbox calls this when the run that used the backend ends.