Skip to main content

gpubox

Rent a GPU box from Vast.ai, RunPod or the VM clouds behind Shadeform, or take one from a Slurm cluster. gpubox checks that it works and manages its teardown. For CI jobs and dev boxes.

Marketplace hosts are unreliable: some never finish pulling the image, some come up with a GPU that is already busy. gpubox rents two at once, keeps the first that passes a health check, and destroys the other. Run gpubox down when done and schedule gpubox reap --namespace NS --destroy as a fallback. Some providers enforce expiry, but others rely on the reaper, as do rentals whose own lease timer never starts or is stopped by preemption.

The controller runs on Linux or macOS with Python 3.10+ and OpenSSH (ssh and ssh-keygen). No third-party Python dependencies. DESIGN.md explains how it works, what it assumes, and what was measured.

Install

pip install gpubox
export VASTAI_API_KEY=...

For a one-off CLI invocation, use uvx gpubox --help. In CI, pin a version (pip install gpubox==0.1.0): the job that runs gpubox holds your provider key. To install unreleased changes, pin a Git commit instead: pip install 'git+https://github.com/tridao/gpubox@<commit>'.

Keys are read from the environment (VASTAI_API_KEY, RUNPOD_API_KEY, SHADEFORM_API_KEY), else from lines NAME=value in ~/.config/gpu-cloud-query/keys.env.

A dev box

gpubox up --gpu "RTX 4090" --max-dph-per-gpu 0.60 --image my/image:tag \
    --namespace dev --name mybox --ttl-min 480 --ssh-config
ssh mybox                      # also scp, rsync, editors
gpubox ssh -- nvidia-smi       # the same with the run's key, no ~/.ssh/config needed
gpubox renew --ttl-min 480     # the lease now ends 8 hours from now
gpubox down

--ssh-config adds a Host mybox entry to ~/.ssh/gpubox_config and one Include line at the top of ~/.ssh/config. down removes the entry.

--gpu can be repeated to accept any of several models (the cheapest offer goes first). --min-cpus and --min-ram-gb are for the whole box; by default it gets max(16, 8 per GPU) CPUs and 32 GB of RAM per GPU. --min-cuda (default 13.0) is the lowest CUDA version the host's driver must support: a CUDA 13.x image runs on any 13.x driver but not on a 12.x one. A box whose driver turns out too old for the image's PyTorch fails without the machine being blamed, and offers with drivers as old are skipped.

A private image: --registry-user USER with the token in GPUBOX_REGISTRY_TOKEN (the registry comes from the image name). Vast and the host's docker daemon see the token, so make it a read-only pull token.

--interruptible rents interruptible boxes, bidding --bid-markup (1.25) times each offer's minimum bid; the price cap applies to the bid with the disk. An outbid box is stopped: its job dies, and the box keeps billing its disk, with its lease timer stopped too, until something destroys it. So run gpubox reap --namespace NS --destroy on a schedule, and expect wait to report a lost job (75). Two launches in different state directories can still bid on one machine at the same moment: the account's boxes are looked at once, when a launch starts. Machines the account already has a box on are skipped (our own bids would outbid each other), and a box that stops or never starts is not held against its machine.

A large image needs a longer --startup-timeout than the default 300 s, which counts from the rental and so includes the image pull.

Jobs

gpubox run --script train.sh --env WANDB_API_KEY --timeout-min 600

run starts the script on the box in a session of its own and streams its output. The job does not depend on the connection: a dropped connection is picked up where it was (for up to --reconnect-min, 10), and Ctrl-C stops the streaming, not the job. --detach prints the job id and returns at once. Then:

gpubox logs -f [JOB]           # its output, until it ends; its exit code
gpubox wait [JOB]              # just the exit code
gpubox jobs                    # every job on the box: exit code, running or lost
gpubox kill [JOB]

(JOB defaults to the newest.) The box itself ends a job at --timeout-min (default 60; 0 for never), with exit 124. --destroy-after destroys the box when the script ends; a job can also run gpubox-destroy-self on the box whenever it is done.

The job sees the image's environment (Docker ENV, saved when the box starts; so do ssh sessions), then --env variables, then GPUBOX_RUN_ID, GPUBOX_JOB, GPUBOX_BOX_INDEX, GPUBOX_BOX_COUNT and GPUBOX_BOX_NAME. gpubox replaces the image's ENTRYPOINT to start its own sshd and timer: a job that needs the entrypoint's setup runs it itself (exec /entrypoint.sh python -m my.job).

Secrets. --env NAME (no =) takes the value from gpubox's own environment, so it is on no command line: op run -- gpubox run ..., a CI secret, Doppler and the like all work the same way. --env-file FILE reads NAME=VALUE lines. Values go over SSH into a file only root can read, which the job reads and deletes as it starts; they are never in Vast's instance settings. The host's operator has root on the machine, so send only credentials you can revoke: scoped, short-lived where possible.

Several boxes

gpubox up --count 4 --gpu "RTX 5090" --max-dph-per-gpu 0.80 --image my/image:tag \
    --namespace eval --name shard --ttl-min 240 --ssh-config
gpubox status                  # shard-0 ... shard-3: addresses, lease
ssh shard-2
gpubox run --box 2 --script job.sh
gpubox run --all --script shard.sh   # on every box: $GPUBOX_BOX_INDEX says which
gpubox down                    # all of them

All or nothing: up races count + --spare hosts and returns 0 only with --count healthy boxes; otherwise it destroys the ones it had. A run of one box is called NAME; a run of several, NAME-0, NAME-1, ...

RunPod

gpubox search --provider runpod --gpu "RTX 4090" --max-dph-per-gpu 0.80
gpubox up --provider runpod --gpu "RTX 4090" --max-dph-per-gpu 0.80 --image my/image:tag \
    --namespace dev --name mybox --ttl-min 240 --ssh-config

The same as on Vast, with RunPod's pods: the race, the gate, jobs, ssh, renew and the lease all work as they do there. RunPod chooses the machine: an offer is a GPU type in a data center that has it in stock, at RunPod's list price, and --gpu matches its names ("RTX 4090" matches "NVIDIA GeForce RTX 4090"; without --gpu, any model under the price cap). A pod deletes itself when its lease ends, with the key RunPod gives each pod. --runpod-cloud community rents community hosts instead of RunPod's own data centers.

As everywhere, --min-cpus and --min-ram-gb default to max(16, 8 per GPU) CPUs and 32 GB per GPU: pass smaller ones to admit RunPod's smaller pods.

Not yet on RunPod: --interruptible, --registry-user (private images) and --exclude-country; and machines are not recorded (RunPod's API does not name them), so the blocklist does not apply. An image that cannot be pulled is not recognised as such: each pod is given up on after --stall-timeout.

Shadeform (VM clouds)

gpubox search --provider shadeform --gpu A6000 --max-dph-per-gpu 0.80
gpubox up --provider shadeform --gpu A6000 --max-dph-per-gpu 0.80 --image my/image:tag \
    --namespace dev --name mybox --ttl-min 120 --overall-timeout 1500
gpubox ssh                     # a shell in the box's container

Shadeform rents VMs on Hyperstack, Massed Compute, Lambda, Crusoe, Nebius and others with one key. A box there is your image run as a container on the VM: gpubox gives the VM a startup script that adds the run's key and starts the image, and reaches the box with SSH to the VM and docker exec, so the image needs no sshd (but, as everywhere, bash and python3). An offer is an instance type in a region, booted with Shadeform's own OS image with the newest CUDA, which must be at least --min-cuda (13.0 by default: pass --min-cuda 12.8 for an image built for CUDA 12). VMs take 5 to 8 minutes to boot; the start-up and stall limits count from when Shadeform expects the boot to end, but --overall-timeout should allow for it.

The lease is Shadeform's own: the VM is created with an auto-delete time, which renew moves. A VM cannot delete itself, so run --destroy-after is refused. Not yet: --ssh-config, --registry-user, --interruptible, --exclude-country, --account-id.

Hyperstack

--provider hyperstack (HYPERSTACK_API_KEY) rents Hyperstack's VMs directly, as boxes like Shadeform's: the image as a container on the VM, reached with SSH and docker exec, booted with Hyperstack's image "with Docker" of the newest CUDA in the region. Hyperstack keeps no expiry and a VM cannot delete itself, so up warns: only gpubox down, or a scheduled gpubox reap --provider hyperstack --namespace NS --destroy, ends a VM left behind. Hyperstack needs a key pair at the create: if the environment has none, the run's public key is imported once as gpubox.

Massed Compute

--provider massed (MASSED_COMPUTE_API_KEY) rents Massed Compute's VMs directly, through its MCP server, as boxes like Shadeform's, on Massed's "Ubuntu Server 22.04 w/ drivers" (NVIDIA drivers and docker). Its 1-GPU products have 6 CPUs and 32 GB: pass --min-cpus 6. Massed cannot rename an instance, so the lease set by up --ttl-min cannot be moved (renew is refused), and as on Hyperstack only down or a scheduled reap ends a VM left behind.

Lyceum

--provider lyceum (LYCEUM_API_KEY) rents Lyceum's VMs, as boxes like Shadeform's. Lyceum runs nothing of ours at boot, so the first probe that gets in sends the box's setup and starts it. Its region and disk (500 GB) are its own choice; as on Hyperstack only down or a scheduled reap ends a VM left behind.

A Slurm cluster

gpubox up --provider slurm --login mycluster --num-gpus 1 --gpu H100 \
    --namespace dev --name mybox --ttl-min 240
gpubox ssh                     # a shell in the allocation
gpubox run --script job.sh     # detached; follows its output
gpubox down

A box is one batch job holding an allocation (--gres=gpu:N, and --min-cpus, --min-ram-gb if given; otherwise the cluster's defaults). gpubox runs Slurm's commands on the login host over your own SSH configuration, so ssh mycluster squeue must work without a password prompt (keys, or a ControlMaster opened beforehand), and the login shell must be POSIX; Slurm must be 20.11 or later (srun --overlap). Everything runs in the nodes' own environment: --image is not used.

--partition, --slurm-account, --qos, --constraint and --sbatch-arg OPTION (repeatable) go to sbatch. A request the cluster can never satisfy (no such partition, too many GPUs, a time limit above the partition's) is a configuration error at once. Time in the queue is nobody's fault: --startup-timeout and --stall-timeout count from when the job starts, and only --overall-timeout bounds the wait. --spare is 0 by default here; a node that fails the gate is excluded from the jobs submitted after it.

The lease is kept twice: by the job's own script, which ends the job when the lease ends, and by Slurm's time limit, set two minutes past it. renew moves both; a cluster that does not let users extend a time limit refuses it, and the box then ends at its old one. Commands reach a box with srun --jobid=ID --overlap, so they get its GPUs (CUDA_VISIBLE_DEVICES), CPUs and environment; jobs started by run are started by the batch script, since Slurm ends whatever a step started when the step ends. The gate looks only at the allocation's GPUs. Not available: --ssh-config, search, and the machine blocklist and reputation store, which are about Vast's machines.

A CI job

- id: up
  run: >
    gpubox up --gpu "RTX 5090" --num-gpus 2 --max-dph-per-gpu 1.25
    --image my/ci-image:tag --namespace my-ci
    --name "${{ github.run_id }}-${{ github.run_attempt }}" --ttl-min 60
- run: gpubox run --script remote.sh --env "SHA=${{ github.sha }}" --timeout-min 40
- if: always() && steps.up.outputs.run_id != ''
  run: gpubox down --run-id "${{ steps.up.outputs.run_id }}"

and, from a schedule every half hour:

gpubox reap --namespace my-ci --destroy

up writes the run id as a step output before it rents anything. Passing it to down lets the teardown work even from a runner that has lost the state directory. Always run down after up, whatever up returned.

From Python

import gpubox

spec = gpubox.Spec(image="ghcr.io/org/img:1", gpus=("RTX 5090", "RTX 4090"),
                   max_dph_per_gpu=1.0, min_cpus=12, min_ram_gb=64, ttl_min=240)
with gpubox.up(spec, namespace="eval", name="shard", count=4) as run:
    jobs = run.start(open("shard.sh").read(), env={"TOKEN": token}, timeout_min=180)
    outcomes = gpubox.wait_all(jobs)   # per job: .code, or .error
# the boxes are destroyed when the block ends, however it ends (run.keep() to keep them)

If up fails or is interrupted after it began the run, it tears the run down before raising (and says how to retry if that fails too). A Run is a handle, not a lock: once the run is torn down or replaced in its state directory, whatever would touch its boxes raises StateError.

gpubox.attach(state_dir) picks up a run left in a state directory (also by the command line); run.boxes[i] has ssh_argv, sh, start, job, jobs; a Job has wait, logs and kill. gpubox.down(run_id=...) and gpubox.reap(namespace) are the teardowns. Failures are exceptions: ConfigError and StateError for our own mistakes, InfraError (NoBoxes, TeardownIncomplete, BoxLost, JobLost) for the provider's or a box's. gpubox.set_log(fn) sends what it says somewhere other than stdout, for the whole process. The command line is a thin layer over this (gpubox/api.py). Elsewhere than Vast, pass provider="runpod", or provider="slurm", options={"login": "mycluster", ...}, to up (and to down(run_id=...), reap and search); a run remembers where its boxes came from.

Commands

up rent boxes (--count, default 1) and wait until they pass the health gate; --provider runpod, shadeform or slurm for those
status show the run's boxes: names, addresses, lease
run start a local script on a box, detached, and stream its output
logs a job's output (-f: until it ends)
wait wait for a job to end
jobs the jobs on a box
kill stop a job
ssh a shell on a box, or -- CMD run there
renew move the end of the boxes' lease
down destroy everything the run rented
reap destroy boxes of a namespace whose lease has ended (without --destroy: report)
search show the offers up would try; rents nothing

Exit codes: 0 ok; 2 configuration (bad arguments, no API key, an image that cannot be pulled or does not start our sshd); 75 infrastructure (no healthy box, box lost mid-run, teardown not confirmed); 124 script timeout; 130 interrupted. run, wait and logs -f otherwise return the job's own exit code.

State lives in --state-dir (default .gpubox): run.json, an SSH key per run, and observations.jsonl.

How it works

  • Race. up rents --count + --spare hosts (2 by default), cheapest first, one machine per host. A box that fails is destroyed and replaced, up to --max-attempts rentals (default 2 * count + 4).
  • Health gate. GPU model, count and VRAM; required URLs reachable (--must-reach); the GPU idle before we touch it. Where the image has a CUDA build of PyTorch, also: CUDA works, a matmul on every GPU matches the CPU, and most of the VRAM can be allocated. It needs python3 in the image.
  • Your own checks. --gate-script FILE runs on each box after the gate passes (by its #! line, else bash; at most --gate-timeout seconds). Exit 0 admits the box; anything else fails it and another is tried. To have the machine blocklisted, print a last line {"ok": false, "reason": "no_network", "detail": "..."} with one of the gate's reason codes (policy.REASONS).
  • Tag. Every box is labelled <namespace>.<name>.<random>.a<n>.<expiry> when it is rented. Anything that knows the run id can find the run's boxes and destroy them.
  • Lease. The lease ends --ttl-min after up started. A timer on the box or the provider enforces it where supported. A scheduled reap destroys expired boxes when there is no timer or it could not run. renew moves the end on providers that support it.
  • Blocklist. A machine that failed in a launch that succeeded is skipped for 2 hours to 14 days, depending on why (observations.jsonl; cache it between CI runs). A launch that failed blames nobody.
  • Defaults from measurement. Hosts in mainland China are skipped (--exclude-country, default CN; none to skip none). A box whose loading status has not changed for --stall-timeout (300 s) is replaced.

What it promises, and what it does not

  • up exits 0 only with --count boxes that passed the gate, were still running when looked up afterwards, and are recorded in run.json. Before that, a failure or Ctrl-C rolls back what was rented. The rollback gets about ten seconds and is an attempt; down finishes it.
  • At most --count + --spare boxes are billable at once, as far as gpubox can know. A rental request that got no answer keeps its slot.
  • No offer above the price cap is rented, whatever the search returned.
  • down exits 0 only when every box it knows of is confirmed gone by id and two listings in a row show nothing with the run's tag. Otherwise it exits 75 and says what is left and what to do.
  • Not promised: a maximum lifetime. With no working lease timer or provider-enforced expiry, a box that down missed can keep billing until the reaper removes it. Nothing here finds a box that was renamed, or that the provider does not list. There is no spending cap across runs.

--account-id (or GPUBOX_ACCOUNT_ID) makes every command refuse an API key that belongs to another account.

Sharing what machines did

Optional. With GPUBOX_STORE_URL and GPUBOX_STORE_TOKEN set, observations of machines are shared through a small Cloudflare Worker (store/), so that a machine that failed for one client is skipped by the others. It is advisory: it costs a command a few seconds at most and never fails it.

Development checks

python3 -m pip install pytest pre-commit
pre-commit install         # lint and format staged Python files with Ruff
pre-commit run --all-files
(cd store && npm ci && npm test)  # Node 24 LTS; also enables the Python/Worker integration test
python3 -m pytest          # fake provider and fake SSH; rents nothing
python3 tests/mutations.py # breaks each behaviour in turn; a test named for it must fail

On PRs and pushes to main, GitHub Actions runs the hooks, tests Python 3.10 and current Python 3, and checks the metadata and installation of both the wheel and the source distribution. The current-Python job also tests the Worker and Python client against local D1. All jobs use GitHub-hosted Ubuntu runners; no GPUs or cloud credentials are needed. Mutation tests run weekly or on demand (Actions → Mutation tests).

Metadata

Release files for gpubox 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gpubox 0.1.0
File Size Uploaded Provenance Actions
gpubox-0.1.0.tar.gz 117.0 kB With provenance Details for gpubox-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for gpubox 0.1.0
File Interpreter ABI Platform Actions
gpubox-0.1.0-py3-none-any.whl Python 3 none any Details for gpubox-0.1.0-py3-none-any.whl

Total release size: 256.4 kB

Release files / gpubox-0.1.0.tar.gz

Download URL gpubox-0.1.0.tar.gz
Size 117.0 kB
Tags Source
SHA-256 checksum
How to use checksums
7a0f6328ba96a512d8b490f9f578ed62932290a9c9e6bfdcef14878a970bda0f
BLAKE2b-256 checksum
How to use checksums
73b15d82060352a13b799fedd90d369871c9b3defe96bb32f0283fcc1d93eed6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.

Transparency log

Release files / gpubox-0.1.0-py3-none-any.whl

Download URL gpubox-0.1.0-py3-none-any.whl
Size 139.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7ce362fa90be3d00a4dd0082a34b7a22a2793b880ee4c7d7c838ea19f7f6139b
BLAKE2b-256 checksum
How to use checksums
68e0b5baf43af31e53b23c3d431c1fef85a8d35761986fa33cfa56ab1afc0bb1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.

Transparency log

Security for gpubox 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for gpubox-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page