Skip to main content

Python SDK for qbox.sh — self-hosted Firecracker code sandboxes

Project description

qbox — Python SDK

The official Python SDK for qbox.sh, the self-hosted Firecracker code-sandbox platform. Mirrors the e2b Sandbox shape so migration is mostly a one-line import change.

pip install qbox-sh
import qbox

with qbox.Sandbox.create(template="python-ml") as sandbox:
    result = sandbox.run_code("import pandas as pd; pd.DataFrame({'a':[1,2,3]}).describe()")
    print(result.text)

Authentication

The SDK reads QBOX_API_KEY and QBOX_BASE_URL from the environment, or you can pass them explicitly / via qbox.configure(...):

export QBOX_API_KEY=qbox_...
export QBOX_BASE_URL=https://qbox.your-company.internal   # self-hosted
qbox.configure(api_key="qbox_...", base_url="https://qbox.acme.internal")

What's included

  • Sandboxcreate / connect / list / get_info / set_timeout / kill, context manager
  • sandbox.commandsrun (foreground + background=True), run_argv, list, connect, kill; CommandHandle streams output
  • sandbox.filesread / write / append / list / stat / exists / remove / rename / mkdir / download / upload
  • sandbox.run_code / run_code_stream / code_contexts — the code interpreter (rich outputs: text/html/png/json)
  • sandbox.shell() — interactive PTY (install qbox[shell])
  • qbox.Templates — read-only list / get
  • Typed errors for every path, env/global/explicit config, transient-only retry, py.typed
import qbox

with qbox.Sandbox.create(template="python-ml") as sandbox:
    sandbox.files.write("/tmp/data.csv", "a,b\n1,2\n")
    out = sandbox.run_code("import pandas as pd; pd.read_csv('/tmp/data.csv').sum().to_dict()")
    print(out.text)
    proc = sandbox.commands.run("python --version")
    print(proc.stdout)

Async (qbox.AsyncSandbox) is planned for v1.1.

CLI

pip install qbox-sh also installs the qbox command (operators may prefer pipx install qbox-sh). It wraps the SDK and adds multi-profile config, rich output, and operator commands.

qbox auth login                         # set base URL + API key (saved to ~/.config/qbox/config.yaml)
qbox doctor                             # end-to-end deployment check
qbox sandboxes create python-ml         # → sb_018f… (prints the id; scriptable)
qbox sandboxes run-code sb_018f -e "print(6*7)"
qbox sandboxes exec sb_018f -- pytest -q
qbox sandboxes files cp ./script.py sb_018f:/tmp/script.py
qbox sandboxes ssh sb_018f              # interactive PTY (needs qbox[shell])
qbox sandboxes kill sb_018f -y

Operator surface: qbox hosts list|drain|cordon|uncordon, qbox api-keys create|list|revoke|rotate, qbox audit logs, qbox templates create|list|delete.

Output: human tables/prose in a TTY, JSON when piped; force with -o json|yaml|table|prose. Multi-profile via --profile/QBOX_PROFILE. Exit codes are documented (0 ok, 2 usage, 3 auth, 4 not-found, 5 transient, 6 conflict, 10 declined, 124 timeout).

Development

pip install -e ".[dev]"
make test        # unit tests
make typecheck   # mypy --strict
make lint        # ruff

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

qbox_sh-1.0.1.tar.gz (127.2 kB view details)

Uploaded Source

Built Distribution

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

qbox_sh-1.0.1-py3-none-any.whl (61.4 kB view details)

Uploaded Python 3

File details

Details for the file qbox_sh-1.0.1.tar.gz.

File metadata

  • Download URL: qbox_sh-1.0.1.tar.gz
  • Upload date:
  • Size: 127.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for qbox_sh-1.0.1.tar.gz
Algorithm Hash digest
SHA256 8a5a6b49de9872480bc7f0a1837b8e0a273a90261563456fcd753d2d195089b5
MD5 41dcf20bef75d45facc6cbf80d757a10
BLAKE2b-256 60dc450c484fd7db2612d53478eeac4fdd81f5eb2d3d73e868f0ab31fb09f51c

See more details on using hashes here.

File details

Details for the file qbox_sh-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: qbox_sh-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 61.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for qbox_sh-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4e71ade0bfd8408b4ac4f6d00c47e06ce030acf03059e13ec73f28f90a2d077c
MD5 5c61e793cc9d487fdb0313574d473a3b
BLAKE2b-256 9824659c12ab058a3ae5a21f3a17d9e6f4122c9f1bfe66aa76aba4d6c96dbb8b

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