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.3.2.tar.gz (146.3 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.3.2-py3-none-any.whl (79.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: qbox_sh-1.3.2.tar.gz
  • Upload date:
  • Size: 146.3 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.3.2.tar.gz
Algorithm Hash digest
SHA256 20d521d98d87935a41977297e3d1ce79c657697e94821ae5bcb6ef51537deb7b
MD5 933c75b618bda4102c9d109466306595
BLAKE2b-256 0f6a73cc6a03440a5809508aa59141c180ee200864d89d6e54799bb20520261d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: qbox_sh-1.3.2-py3-none-any.whl
  • Upload date:
  • Size: 79.0 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.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 30dd656091f5ffdefa8e3baaa62b88a8e18f3c48409772521cd6ed02cac06168
MD5 500b4b067b0d86586480c25a21f16d03
BLAKE2b-256 23be1e859073b2145033a8b8e656283d542bad8d0d6f2df69b1e42e888e6acf8

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