Skip to main content

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

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="")

Examples

Runnable examples are available in the examples/ directory:

Example Description
01_hello_world Basic sandbox usage
02_context_options Context configuration options
03_files File read/write/list operations
04_streaming Streaming execution output
05_templates Working with sandbox templates
06_volumes Persistent volumes and snapshots
07_webhook Webhook event delivery
08_network Network policy configuration
09_expose_port Exposing ports publicly

Run an example:

cd examples/01_hello_world
SANDBOX0_TOKEN=your-token python main.py

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",
        )
    ],
    wait_for_mounts=True,
    mount_wait_timeout_ms=45000,
)

for mount in sandbox.bootstrap_mounts:
    print(mount.sandboxvolume_id, mount.state)

Links

License

Apache-2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sandbox0-0.2.2.tar.gz (132.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sandbox0-0.2.2-py3-none-any.whl (436.7 kB view details)

Uploaded Python 3

File details

Details for the file sandbox0-0.2.2.tar.gz.

File metadata

  • Download URL: sandbox0-0.2.2.tar.gz
  • Upload date:
  • Size: 132.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for sandbox0-0.2.2.tar.gz
Algorithm Hash digest
SHA256 f617645ca7d31d4a38a1e42d62836b703028ba82a236fb6c753c44fd312df324
MD5 69d895cc413eeffb5825bea563a48131
BLAKE2b-256 8df8b94be18f63a0f153285b7fc548f08706f4f5d6a2ee9c67aed8c5358f3684

See more details on using hashes here.

File details

Details for the file sandbox0-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: sandbox0-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 436.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for sandbox0-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 cf7a5b7e752085a15945165db9dfb603da4eef5348013dc7855be8e20f9ede91
MD5 9438bd6e74528db0a6c737067c4bb448
BLAKE2b-256 fa2ab43b8e946b013373ee9efaf9e1d7eefbe60ebd7b3b7413c2a556931baf3b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page