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, 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}")

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",
        )
    ],
    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.4.tar.gz (135.3 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.4-py3-none-any.whl (440.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sandbox0-0.2.4.tar.gz
  • Upload date:
  • Size: 135.3 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.4.tar.gz
Algorithm Hash digest
SHA256 6c6687a7d6bf77205320646a8439ff4f529feddeedd470f53bab1ae4c559e66f
MD5 cfd5edc456edbea82debbba1d5da0911
BLAKE2b-256 83180eee56e8af3554066a1c325794eac442421c1e8a78178209ee9bf60437d4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sandbox0-0.2.4-py3-none-any.whl
  • Upload date:
  • Size: 440.6 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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 8488d3b34bd4de85271881d608b75c1dafa4771c24a5a69b75938655b2af62cd
MD5 e817b6c97bf41ed221f292ccdb50aa87
BLAKE2b-256 eee3dedb15a4a1b0f79a35840dbdb22fbb524d0d1ffca8c7e2726e4e79caca1d

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