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.4.0.tar.gz (146.6 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.4.0-py3-none-any.whl (79.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: qbox_sh-1.4.0.tar.gz
  • Upload date:
  • Size: 146.6 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.4.0.tar.gz
Algorithm Hash digest
SHA256 203a6282f46a870205fae4afda8bf043bfcd7ca9ecb66eadd260cb41e06bf7bf
MD5 d8c4940378cb8580fe7e2f2d74de23b7
BLAKE2b-256 64e944052a7e300650dee3064a980e9d414bb733a8ced3c4af94c2c4e64a2042

See more details on using hashes here.

File details

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

File metadata

  • Download URL: qbox_sh-1.4.0-py3-none-any.whl
  • Upload date:
  • Size: 79.3 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.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a419a2ad2ec4cc26d92ca32db2b18bb2c8e1071b332a9c910548068181d94330
MD5 ab3fe3a546cd961c450c5b58bda1e23c
BLAKE2b-256 155c98e8ebfa008863597a043ae24a16a63759698eb3eef5e7df4ef0a19930d6

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