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.0.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.0-py3-none-any.whl (61.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: qbox_sh-1.0.0.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.0.tar.gz
Algorithm Hash digest
SHA256 2b531f13a82c3d08bb74ceedc046e252e7d44144684c2aac847390f30009507f
MD5 3d85731305b02d588cc3a4f5509a861b
BLAKE2b-256 c4f6b8cc8fc89e712d9c896dbeb3c51b274f67f7fd326f8d835616191d702ab8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: qbox_sh-1.0.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1d78acfa573e81aa7dfa98693fd4059d9052719d21de093c45f1394b37882b5b
MD5 f206021a4aba816c3a301c9932238cd7
BLAKE2b-256 4dc89f4a2c01d61c961bed7882b805281dc06e0d9e12f77383e2ac2eb1cc867b

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