Skip to main content

aice-sandbox

Python SDK for the AICE Sandbox Service: isolated gVisor sessions an agent can run code in, and links to the files it produces. Same auth, transport and error model as every other AICE SDK (aice-core).

Install

Not on PyPI yet. From this workspace:

pip install -e ../core -e .

Quick start

from aice_sandbox import SandboxClient

client = SandboxClient(
    base_url="http://localhost:8080",
    api_key=PROJECT_KEY,          # console project key; its aud must include "sandbox"
    user_id="3fa85f64-5717-4562-b3fc-2c963f66afa6",   # the user you act for
)

session = client.session.create()                  # tenant comes from the key
result = session.exec(["python3", "-c", "print(6 * 7)"])
print(result.stdout)  # "42"

session.write("data.txt", b"some content")
content = session.read("data.txt")
files = session.list()
session.destroy()

Act for a different user on one call with aice_core.acting_as(user_id). A session created under one project's key is invisible (404) to every other project's key.

session.create(manifest={"network": "install_only"}) allows session.install([...]) through the service's egress proxy; the default session has no network.

Getting files out: artifacts

A session's files live in a tmpfs that disappears with the session. To hand one to a user, publish it: the service copies it to its artifact store (MinIO/S3) and returns a presigned link.

session.exec(["python3", "-c",
              "import matplotlib.pyplot as plt; plt.plot([1, 3, 2]); plt.savefig('chart.png')"])
art = session.publish("chart.png")
art.url         # presigned GET link, valid until art.expires_at (1 h by default)
art.mime        # "image/png"
art.artifact_id # keep this, not the url

# Later, after the link expired or the session is gone:
art = client.artifacts.url(artifact_id)

Any file type works, up to the service's size limit (25 MB by default). The artifact belongs to the acting user: another user, or another project's key, gets ArtifactNotFoundError. client.artifacts.url also works for files an agent published with the sandbox MCP tool publish_file.

mime tells a frontend how to show the file. Images (image/png, image/jpeg, …) go in an <img>. application/vnd.plotly.v1+json (a *.plotly.json file written with fig.to_json()) is an interactive chart: fetch it and call Plotly.newPlot(el, spec.data, spec.layout). Anything else is a download named filename. The service's README ("Artifacts") has the full table. The sandbox image preinstalls numpy, pandas, matplotlib and plotly.

Project admins (user_role="admin", "owner" or "service_role") can read and change their own project's container mode:

client.tenant_config.update(project_id, {"container_sharing": "shared"})

Errors

Every exception derives from SandboxSDKError (itself an aice_core.AiceError):

Exception When
AuthenticationError 401: key missing, invalid, expired or not issued for sandbox; or no user_id
ForbiddenError 403: e.g. tenant config without an admin role, or for another project
NetworkNotPermittedError 403 from install(): the session's manifest grants no network
SessionNotFoundError 404: the session never existed, was destroyed, or belongs to another project
SandboxFileNotFoundError 404 from read() or publish(): no such file in the session
ArtifactNotFoundError 404 from artifacts.url(): no such artifact for this project and user
QuotaExceededError 429: .scope is "user", "tenant" or "global", .limit the cap

On a service with no artifact store, publish() and artifacts.url() raise SandboxSDKError with .code == "artifacts_disabled".

Testing

pytest

Uses respx to stub the HTTP layer. End-to-end coverage against a real service is in the sandbox service repo's own suites, which use this package.

Metadata

Release files for aice-sandbox 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aice-sandbox 0.2.0
File Size Uploaded Provenance Actions
aice_sandbox-0.2.0.tar.gz 12.0 kB Without provenance Details for aice_sandbox-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for aice-sandbox 0.2.0
File Interpreter ABI Platform Actions
aice_sandbox-0.2.0-py3-none-any.whl Python 3 none any Details for aice_sandbox-0.2.0-py3-none-any.whl

Total release size: 20.9 kB

Release files / aice_sandbox-0.2.0.tar.gz

Download URL aice_sandbox-0.2.0.tar.gz
Size 12.0 kB
Tags Source
SHA-256 checksum
How to use checksums
6982a93decd5ad2696b18e0e7a7052a40536add631d3839ce7c043789f7d9709
BLAKE2b-256 checksum
How to use checksums
258cdd18324d657065ba1a31135a643a20acbb7fb1e505fb4a6fa848447f19c9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.24

Release files / aice_sandbox-0.2.0-py3-none-any.whl

Download URL aice_sandbox-0.2.0-py3-none-any.whl
Size 8.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
383d825cc1d57471f552e4771946a2352e70b35ad430c35b33750f9764995bd1
BLAKE2b-256 checksum
How to use checksums
413bd534468cc634eff186e11f1889a94e90b9f37ae3868271cb6d6c8ec4b2a6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.24

Security for aice-sandbox 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page