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.1.tar.gz (146.1 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.1-py3-none-any.whl (78.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: qbox_sh-1.3.1.tar.gz
  • Upload date:
  • Size: 146.1 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.1.tar.gz
Algorithm Hash digest
SHA256 eff7b84c131b29e72bca5cd63581d811b28fd0e17a441db969a543ff7ea43cd6
MD5 47660ead97de0ecf9708fca9587ae31a
BLAKE2b-256 7f7ab766c0449dcbb0a4ef25d745025b2807cf4a34a8674af3053979880ded2f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: qbox_sh-1.3.1-py3-none-any.whl
  • Upload date:
  • Size: 78.8 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5fac4b69bb044b9b0b8f46aebf377f0fd8de150a93c4d94bb57877546969b91e
MD5 545279b0ce86324f5f977e2c1cfbc77c
BLAKE2b-256 e839f5cac5f4754b297721576f570f18ffdf5f5107477717d9d7d6cb64a0f5da

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