Pool fragmented GPUs for many coding agents.
Local GPUs, your own servers and rented clouds behind one lease API, for agents whose sandboxes have no GPU.
Blog post · Technical report · Agent guide · Integrations · Experiments
Coding agents now write the kernels, inference servers and experiments behind the next models, and every step of that loop runs on GPUs. Two things waste the GPUs a lab has:
- Agents hold GPUs they are not using. An agent spends most of its session reading, thinking, editing and compiling. In our runs, a GPU attached to an agent's session ran jobs only 28–43% of the time it was held, while other agents waited up to 73 minutes for one.
- The GPUs a lab can reach are fragmented: a few free cards on servers shared with people, other servers it owns, and credits at several clouds, each with its own interface, start-up time and billing.
GPULake pools them. Agents work in sandboxes with no GPU, compile there, and submit short GPU jobs. Each job runs with the agent's own files and software, on whichever GPU the scheduler picks: a local GPU, a container on an owned server, or a rented machine on RunPod, Vast.ai, Modal or Daytona. A GPU is held only while it computes, and the operator's limits and budgets are enforced from outside the agent.
Eight Claude Code and Codex agents build an inference server on two H200s. (a) Each agent holds a GPU for its session: 57% of held GPU time runs no job, and agents wait up to 73 minutes. (b) With GPULake, agents submit short jobs: every agent has a GPU within 1.5 minutes, and no GPU time is held without a job.
| Result | Setting |
|---|---|
| 49 → 0.4 min | median wait for an agent's first GPU, holding vs. sharing two H200s (8 real agents) |
| 57% → 0% | of held GPU time with no job running, in the same runs |
| 8 agents, 1 GPU | build LLM and TTS inference servers on one H200; all pass their quality gates, at 7–24× (Qwen) and 415–665× (TTS) the reference |
| 98% | of a 5-hour run one L40 was held, by four agents on kernel, image and video tasks that each beat SGLang |
| 4 / 4 graded | with a rented machine killed every 2 minutes under real agents |
- Short jobs, not sessions.
gpurun submitqueues a GPU step with its own short lease and returns at once; the agent keeps working and collects the result later. Leases remain for interactive work, such as a server the agent queries from its sandbox. - Scheduling. Priorities and EASY backfilling, so short jobs with honest limits fill gaps; a GPU passes to the next job 0.07 s after the last exits; idle leases are reclaimed; other users' processes are detected and left alone.
- The environment travels with the work. Locally, a job shares the sandbox's image, files and
localhost. Remotely, the machine runs the sandbox's image, only changed files are sent, and each agent's environment is saved between machines. - One pool, many sources. Local GPUs, servers you own (SSH), RunPod, Vast.ai, Modal and Daytona behind one lease interface, in your order of preference. The coordinator does not even need a GPU of its own.
- Limits enforced from outside the agent. Per-agent and per-user limits, GPU-hour budgets, spending caps, tokens bound to their sandbox, and job containers that see only their own GPUs. Agents are charged only for usable time.
- Written for models. A CLI and MCP tools with the same operations, an Agent Skill for Claude Code and Codex, and replies that say why a request waits, when to retry and what changed.
- Built to fail safely. Retries, cool-downs, reruns of lost jobs, a sweep for leaked machines, and a coordinator that picks up where it left off after a restart.
git clone https://github.com/Infini-AI-Lab/GPULake && cd GPULake
uv venv .venv && uv pip install -e '.[test]'
cp examples/config.yaml ~/.gpulake.yaml # set pool.initial to the GPUs agents may use
.venv/bin/gpu-coordinatord -c ~/.gpulake.yaml
.venv/bin/gpuctl -c ~/.gpulake.yaml statusStart an agent's sandbox. gpuctl docker-args issues a token bound to that container and mounts the client:
docker run -d $(gpuctl docker-args --user alice --agent agent-17 --container agent-17) \
-v /path/to/ws:/work -w /work my-agent-image sleep infinityInside the sandbox, the agent compiles without a GPU and submits GPU steps:
gpurun gpus # the GPUs, and what to compile for
nvcc -arch=sm_90 -O3 -o bench bench.cu
J=$(gpurun submit -q -g 1 -t 3m -p "bench v3" -- ./bench) # returns at once
gpurun job $J --wait 600 # exits with the job's exit codeAdd rented GPUs by listing them in the pool after your own (local GPUs first, the cloud takes the overflow):
pool:
initial: [6, 7, "runpod:0", "modal:0"]
backends:
runpod:
{provider: runpod, api_key_file: ~/.gpulake/runpod_key,
gpu_type: "NVIDIA H100 80GB HBM3", slots: 1, spend_limit_usd: 20}
modal:
{provider: modal, token_file: ~/.gpulake/modal, gpu_type: [L4, A10G], slots: 1}docs/AGENT_GUIDE.md: the guide written for models. It covers how leases and jobs work, the rules, recipes, and what to do for each error.integrations/: a shared Agent Skill,CLAUDE.md/AGENTS.mdblocks, MCP and harness configs, an in-sandbox installer, andlaunch_agent.py, which runs Claude Code or Codex in a gpulake sandbox:integrations/launch_agent.py --agent claude --name alice-t7 --workspace ~/work/t7 --image IMG --prompt "..."
integrations/harbor/: Harbor evaluation jobs. Setenvironment.import_path: gpulake_harbor:GpulakeDockerEnvironment. Each trial then runs in a GPU-less sandbox with its own gpulake identity and the harness files above. The verifier leases the task'sgpus = Nfor the tests. Leases, job containers and tokens are cleaned up at trial end, and per-trial GPU-hours go togpulake_usage.json.
The details behind each part, for operators and developers.
Running without local GPUs (a laptop, a CPU server)
The coordinator does not need local GPUs. On a machine without NVIDIA drivers it starts with an empty local
inventory (server.local_gpus: auto, the default, logs no local GPUs; false skips NVML), and the pool is
made of rented GPUs only: RunPod, Vast.ai, Modal (see GPU backends). It needs Docker for the agents'
sandboxes, and ssh-keygen only for RunPod / Vast.ai.
server: {local_gpus: false}
pool:
initial: ["modal:0", "runpod:0", "vast:0"] # every GPU is rented when a lease is granted
backends:
modal: {provider: modal, token_file: ~/.gpulake/modal, gpu_type: [L4, L40S], slots: 1,
image: nvidia/cuda:12.8.1-devel-ubuntu24.04, spend_limit_usd: 5}
runpod: {provider: runpod, api_key_file: ~/.gpulake/runpod_key, gpu_type: "NVIDIA GeForce RTX 4090", slots: 1,
image: nvidia/cuda:12.8.1-devel-ubuntu24.04, spend_limit_usd: 5}What changes for agents: every job runs on a rented machine, with its working directory copied there and
back (--sync DIR for another directory); gpurun gpus says the server has no GPUs of its own and
--backend local is refused with that reason. A Harbor grader (gpulake_verifier_backend: auto) then
also runs on a rented GPU, with /tests copied up and /logs/verifier (its reward) copied back.
Validated: the coordinator in a container without NVIDIA devices or NVML (Modal T4 jobs through gpurun),
and real agents with harbor_demo.py --gpu none (experiments/timeshare/RESULTS.md, E7).
Deploying as a service, and launching sandboxes
cp examples/config.yaml ~/.gpulake.yaml # pool.initial: [4, 5]
cp examples/gpulake.service ~/.config/systemd/user/
systemctl --user daemon-reload && systemctl --user enable --now gpulake
loginctl enable-linger $USER # keep it running after logout
tail -f ~/.gpulake/daemon.log # the user journal may not be readable here
gpuctl -c ~/.gpulake.yaml status- The unit restarts the daemon if it crashes.
- Leases and jobs live in SQLite (
~/.gpulake/gpulake.db). Running job containers are re-attached after a restart or crash. - More than one coordinator can share a Docker host. Give each its own
server.instance, port, admin socket and database. Job containers are named<instance>-j<N>and labelledgpulake.instance=<instance>, so one coordinator never adopts or removes another's jobs.
Launch a sandbox (see examples/launch_sandbox.sh):
docker run -d $(gpuctl docker-args --user alice --agent agent-17 --container agent-17) \
-v /path/to/ws:/work -w /work my-agent-image sleep infinitydocker-args creates a token bound to that container name and prints
--name … --env-file ~/.gpulake/env/<user>--<agent>.env -v …/client/gpurun:/usr/local/bin/gpurun:ro.
The env file sets GPULAKE_URL and GPULAKE_TOKEN. Give each sandbox its own agent name.
Sandboxes on any user-defined bridge network can reach the host at the docker0 IP
(often 172.17.0.1; see ip addr show docker0). A sandbox with --network none cannot reach the coordinator.
Agent interface: gpurun, MCP tools, notices, claim deadline
Shell (client/gpurun, Python 3.6+ standard library only):
gpurun request 2 0.5 -p "TP2 decode bench" # exit 0 granted, 3 queued, 4 denied (JSON on stdout)
gpurun wait L3 # if queued
gpurun L3 -- python bench.py --tp 2 # streams output, returns the command's exit code
gpurun --detach L3 -- python -m sglang.launch_server --port 30000 # then curl localhost:30000
gpurun logs -f J7 ; gpurun stop J7
gpurun extend L3 0.5 ; gpurun release L3 ; gpurun status
gpurun batch -g 1 -t 0.25 -p "unit tests" -- pytest tests/gpu # request+wait+run+release
J=$(gpurun submit -q -g 1 -t 3m -p "bench v3" -- ./runs/v3/bench) # queue a job, return at once (J9)
gpurun job $J --wait 600 ; gpurun logs $J # its exit code / output; `last` = newest job
gpurun submit -g 1 -t 3m --wait-end 900 -- ./runs/v3/bench # submit + wait + print output, one call
gpurun gpus # GPU model + what to compile for (nvcc -arch=sm_90, TORCH_CUDA_ARCH_LIST), no GPU neededSharing a GPU between many agents: gpurun submit. An agent iterating on GPU code (write, compile,
benchmark, repeat) needs the GPU only while a benchmark runs, a small share of its time. A lease held for
the whole session blocks everyone else while the agent thinks. A submitted job holds the GPU only while it
runs:
gpurun submit(MCPgpu_submit) returns ajob_idat once; the job isqueueduntil GPUs are free, then starts by itself and ends its lease when it exits. No claim and no release are needed; the agent's next call carries a noticeJ9 (…) exited with exit code 0, ran 12s.- The agent keeps working meanwhile (preparing the next candidate), then collects the result with
gpurun job J9 --wait N(exits with the job's exit code) orgpu_logs(job_id, wait_s). -tis the job's time limit. Short honest limits start sooner (backfill) and are enforced like lease hours.- With
--snapshotthe sandbox is captured at submit time, so the job runs the code the agent had then, even if it keeps editing. Without it the job reads the shared workspace when it starts. - The job's environment (it may hold secrets) stays in the coordinator's memory and is never written to its database. After a coordinator restart, a still-queued job gets the sandbox's own environment.
gpurun stop J9cancels a queued job, or one still waiting for its rented machine to boot. Policy limits apply as for leases (a submission is a lease request;max_pending_requestscaps how many an agent queues). A denial for a limit says what the agent has in flight;--retry-denied -w 1800queues the job as soon as the limit allows.-t/hourstake durations (3m,90s,1h) or hours (0.05), on the CLI, HTTP and MCP.- A submit whose program (
./runs/v3/bench) or script (python bench.py) does not exist in the sandbox is refused at once, instead of failing after its wait in the queue (and, on a rented GPU, a machine boot).
Agents see why they wait. A queued request or job has waiting_for: the requests ahead of it, and what
each GPU it could get is doing (held by a lease until when, busy with another user's work outside the
coordinator, settling, a backend not renting). A job starting on a rented machine says it is booting (and
that its clock starts once it is up) or copying the working directory. run_s is the job's own time; boot and
copy are setup_s. A local job's start (its snapshot and docker run) is not charged either: while a lease's job
is starting the lease neither expires nor is reclaimed, and its clock (and GPU-hour charge) starts when the job
runs. On a shared host whose Docker daemon stalled behind other users' image builds, 43 of 112 jobs started more
than 30 s after their grant (up to 9 minutes) and 8 leases ran out before their job ran; that time was 2.1 of 7.3
GPU-h charged. Built from mining 26 real agent trials (303 GPU jobs): queued agents polled up to 23 times
for a job blocked by another user's processes, with nothing telling them why.
experiments/timeshare/ measures the effect with emulated and real agents sharing one GPU.
- While a foreground job's output streams,
gpurunchecks its lease every 20 s. When the lease nears expiry it prints a warning to stderr at 10, 5, 2, 1 and 0.5 minutes left, e.g 8000 .gpurun: warning: lease expires in 2 min … (gpurun extend L3 <hours> to extend). After agpurun extend, the warnings start over for the new expiry time. - Pre-expiry signal (opt-in): with
gpurun --notify-signal USR1 [--notify-before 5m] L3 -- cmd(ornotify_signalon thegpu_runMCP tool), the command gets that signal once, at the given time before expiry, and again before each new expiry if the lease is extended.- The program must handle the signal: most signals terminate a process that doesn't. For example:
signal.signal(signal.SIGUSR1, save_checkpoint). - The signal goes to the command's main process. If you wrap the command in
sh -c, useexecso your program is that process.
- The program must handle the signal: most signals terminate a process that doesn't. For example:
- Ctrl-C or SIGTERM to a foreground
gpurunstops the job. - If the client is killed with SIGKILL or the connection drops, the job is stopped
after
attach_grace. - The job inherits the client's environment, current directory and uid.
CUDA_VISIBLE_DEVICESis dropped, so the job's GPUs are numbered 0..N-1.
MCP at $GPULAKE_URL/mcp, with Authorization: Bearer $GPULAKE_TOKEN.
Tools: gpu_request, gpu_wait, gpu_extend, gpu_release, gpu_status, gpu_info,
gpu_run, gpu_submit, gpu_logs and gpu_stop. The server's MCP instructions explain the workflow to the agent.
claude mcp add --transport http gpu "$GPULAKE_URL/mcp" --header "Authorization: Bearer $GPULAKE_TOKEN"Responses are written for agents. A denial carries a reason, and a retry_at
when waiting will help. A queued lease carries queue_position and eta. When a
lease nears expiry, warnings say so.
How agents learn that a queued request was granted.
- Every JSON response, REST or MCP, carries
noticesabout any of the agent's leases that changed state since it last heard. That covers grants, a grant that went back to the queue, and leases that expired, were reclaimed, revoked or cancelled. - Each notice is delivered once.
gpurunprints notices to stderr asgpurun: notice: L12 was granted: GPUs [4, 5] …. - An agent that wants to hear about a grant right away keeps waiting on it with
gpu_wait, or runsgpurun wait L12 -t 3600in the background. In Claude Code, Bash'srun_in_backgroundwakes the agent when the wait exits.
Claim deadline (policy.claim_deadline, default 5 min; 0 turns it off).
- A grant made while the request was queued is unclaimed until the agent is told about it, by any response that shows the lease or carries the notice.
- The lease's hours and the charging start at the claim, not at the grant.
- If the agent makes no call within the deadline, the GPUs go to the next request and the agent's request returns to the end of the queue. The agent gets a notice saying so.
- A second missed claim cancels the request.
Scheduling and policy
- Leases:
queued → granted → released | expired | reclaimed | revoked | cancelled. - Scheduler: FIFO within each priority level, with EASY backfill. The head of the queue gets a reservation at the time enough leases expire. Later requests run first only if they end before that time or don't need the reserved GPUs. Declared hours are what make this possible.
- Policy (
policy:in the config;gpuctl reloadapplies changes):- Per-agent limits: GPUs per lease, hours per lease (longer requests are clamped, with a note), concurrent GPUs, pending requests, number of extensions.
- Per-user limits: the same kinds of limits, summed across all of the user's agents.
- Budgets are in GPU-hours over a rolling window, e.g.
2 GPU-h / 8hplus12 GPU-h / 7d. - Admission rule: used + reserved + requested ≤ budget, where "reserved" is the remaining declared time of granted leases plus queued requests. Only time actually held is charged.
- Extensions are refused while other requests are waiting.
- Pool: set by
pool.initialon first start, then managed withgpuctl pool add 3andgpuctl pool remove 5 [--now].- Removal drains by default: the GPU leaves the pool when its lease ends.
--nowrevokes that lease instead. - Requests bigger than the pool are denied immediately.
- Removal drains by default: the GPU leaves the pool when its lease ends.
- Foreign use, before a grant: a pool GPU that isn't leased but has processes or memory in use
(someone working outside the coordinator) is skipped. It becomes allocatable again
after
settleidle seconds. - Foreign use on a leased GPU: each tick, every process on a granted lease's GPUs is attributed via
NVML (pid) →
/proc/<pid>/cgroup(container) → the job container'sgpulake.leaselabel.- Who counts as foreign: anything that isn't one of the lease's own job containers, such as another user's host process or another container.
- What happens: the coordinator never touches the foreign process. It:
- tells the agent once per episode (a notice on its next call; the lease view gets
foreignand a warning;gpurunprints it during a run); - shows
SHAREDingpuctl status; - logs the event;
- adds the shared time to the lease's
contended_s, which is kept on the ended lease and in usage reports; - makes the GPU wait out
settlebefore it is granted again.
- tells the agent once per episode (a notice on its next call; the lease view gets
- Charging is unchanged.
- Host-token (cooperative) leases are exempt: the agent runs on the GPU directly, so its processes can't be told from anyone else's.
- NVML shows memory in use but no processes: this counts as foreign use too, once it has lasted
pool.hidden_grace(default 10 s). The same state shows for a moment while a CUDA process starts or exits (nvcc -arch=native's GPU probe,ncu,nsysin the lease's own job); counting those blips made the GPU sit out a settle period after the lease for nothing. - The first warning of an episode is logged with each unattributed PID's cgroup and command line.
- Snapshots (opt-in): by default a job runs on the sandbox's image, and only the sandbox's volumes are
live. A snapshot job instead starts from
docker commit --pause=falseof the sandbox, so it sees everything the agent changed: patched installed libraries, pip installs, files outside the volumes.- Volumes stay live as before. Writes the job makes elsewhere are not copied back.
- The snapshot image is removed when the job ends; leftovers from a crash are pruned.
- Cost: one commit per job, about 1–2 s for small changes, longer after large installs; the time is
recorded as
snapshot_sin the job view. - Precedence: per job
gpurun --snapshot/--no-snapshotorgpu_run(snapshot=…)> the caller's or the sandbox'sGPULAKE_SNAPSHOT>runner.snapshot(default false).
- Idle reclaim: a granted lease with no running jobs and no GPU activity of its own for
idle_reclaim(15 min) is ended; while another agent's queued request could use its GPUs, afteridle_reclaim_contended(5 min), and the lease's warnings say so. Another user's process on its GPUs doesn't keep it alive. (With real agents holding leases for whole sessions, 57% of held time was idle while others queued up to 73 min.) - Hand-off: released GPUs are re-read every 100 ms for up to 3 s and given to queued work as soon as they are clear (an exiting CUDA process stays visible to NVML for a moment). 8 emulated agents with real kernels, run side by side: mean idle gap between jobs 0.284 s -> 0.073 s (p90 0.653 -> 0.124 s).
- No agent can spend another agent's GPU-hours:
- Leases, jobs and budgets are keyed by
user/agent. An agent can only see, run on, extend or release its own leases and jobs; any other ID returns 404. - Sandbox tokens (the default) are accepted only from their own container: the container named at creation, or the first sandbox that uses the token. A copied token gets 403 from any other container, from the host's 127.0.0.1, and from unknown addresses.
- Host tokens (
gpuctl token create --host) are for agents running directly on this machine. They are accepted only from 127.0.0.1 and can't start jobs. - One running sandbox per agent name. A token for a name already used by another running sandbox is refused, with 409 at creation or 403 on first use. Tokens of sandboxes that are gone are revoked, so the name can be reused.
gpuctl docker-argswrites the token to a mode-600 env file (~/.gpulake/env/) and passes--env-file, so the token never appears on a command line, where other host users could see it inps.gpuctl token revokedeletes that file.- GPU handoff: a GPU from an ended lease isn't granted again until every job container
of that lease is gone.
docker stopcan take up tostop_timeout, and a stuck process can take longer. Until then the old lease is still charged, andgpuctl statusshows the GPU as blocked by that job. The next agent never pays for, or shares a GPU with, the previous agent's leftover processes. - When a sandbox container disappears, its agent's leases are released.
- Leases, jobs and budgets are keyed by
- Restart-safe: leases and jobs live in SQLite. Running job containers are re-attached when the daemon starts again.
GPU backends: local GPUs, your servers (SSH), RunPod, Vast.ai, Modal, Daytona
Every pool GPU belongs to a backend, and the coordinator talks to all of them through one interface
(gpulake/backends.py): an inventory of GPUs, and a runner that starts, follows, signals and stops jobs.
- local (always): this host's GPUs. A job runs in a container next to the agent's sandbox, sharing its volumes and localhost (above).
- remote (
backends:in the config,gpulake/remote.py): machines rented on demand. A backend hasslotspool GPUs, named<backend>:0,<backend>:1, ...; add them to the pool like local GPUs. Providers:runpodandvast(machines reached over SSH),modalanddaytona(sandbox platforms driven through their Python SDKs:pip install 'gpulake[modal]'/'gpulake[daytona]'; no SSH),ssh(GPU servers you own or may use, reached over SSH: below), anddocker(a container on this host stands in for the rented machine: the whole remote path, for free, for tests and demos).
pool:
initial: [6, 7, "runpod:0", "runpod:1"] # local GPUs first: the cloud takes the overflow
backends:
runpod:
provider: runpod
api_key_file: ~/.gpulake/runpod_key # or RUNPOD_API_KEY
gpu_type: "NVIDIA H100 80GB HBM3" # RunPod gpuTypeIds (a list tries several); Vast: gpu_name
slots: 2 # at most this many GPUs rented at once
image: runpod/pytorch:2.4.0-py3.11-cuda12.4.1-devel-ubuntu22.04
keep_warm: 10m # a released machine waits this long for its agent's next lease
spend_limit_usd: 20 # no new machines once the estimated spend reaches this
sync_max_mb: 2048 # largest working directory a job may copy
# vast: {provider: vast, api_key_file: ~/.gpulake/vast_key, gpu_type: "RTX 3090", slots: 1,
# image: pytorch/pytorch:2.4.0-cuda12.4-cudnn9-runtime, max_price_per_hour: 3,
# min_reliability: 0.97, min_inet_down_mbps: 200} # picks the cheapest offer that qualifies
# modal: {provider: modal, token_file: ~/.gpulake/modal, gpu_type: [L4, A10G, T4], create_wait: 2m,
# slots: 1, image: nvidia/cuda:12.8.1-devel-ubuntu24.04}
# daytona: {provider: daytona, api_key_file: ~/.gpulake/daytona, gpu_type: RTX-4090, usd_per_hour: 0.6,
# slots: 1, image: nvidia/cuda:12.8.1-devel-ubuntu24.04}
# sim: {provider: docker, gpus: [3], image: my-cuda-image, slots: 1}
# lab: {provider: ssh, host: gpu-server.example.edu, user: me, gpus: [4, 5, 6, 7],
# keep_warm: 10m} # image: sandbox by default; pool: "lab:0", ...Your own GPU servers over SSH (provider: ssh). For GPUs on machines other than the coordinator's host,
e.g. a lab server you can ssh into, that has Docker with the NVIDIA runtime:
host,user,port,ssh_keyare optional: by default it is your own SSH setup (~/.ssh/config, agent, known hosts). One SSH connection per server is shared (ControlMaster), so polls and log follows are cheap.gpus: the server's GPU indices this backend may use (default: all). Slot<name>:iis GPUgpus[i]there, andslotsdefaults to their number. Add the slots to the pool like any other GPUs.- A lease gets a container on the server with exactly its leased GPUs (
docker run --gpus "device=..."), created in seconds and kept warm for the same agent like a rented machine; jobs run in it throughdocker execover SSH. Nothing is billed (usd_per_hourto account for it anyway).docker_argsaddsdocker runflags (--cpus,--memory,--network host, ...);shm_sizedefaults to 16g. - A job sees what it would see on a local GPU:
- the sandbox's own image (
imagedefaults tosandbox): same Python, packages, toolchain, glibc; - its working directory, synced before each job: only what changed since the machine last got it is sent,
and what the agent deleted is deleted there. Workspace venvs and
node_modulesare included (they run there: same image, same paths);sync_excludedefaults to__pycache__,*.pyc. Files the job creates or changes come back when it exits (and are not sent again); - with
--snapshot, the sandbox's own filesystem changes (whatdocker commitcaptures for a local job:pip installinto the system Python, patched site-packages, files outside the volumes), applied to the container the same incremental way (docker diffof the sandbox, then only the entries whose type, mode, size or times changed). Logins are never copied (below). - Not shared: other volumes, and the sandbox's localhost (a server a job starts is on the server, not on the
agent's
localhost). Writes a job makes outside its working directory stay in the lease's container (a local snapshot job's are discarded). - Measured on a 10x L40 server over the LAN: the first job of a lease (system
pip install, a patched stdlib file and a workspace venv) started in 4.3 s, copying 2.7 s; after a package upgrade 3.9 s; nothing changed: 1.0 s.
- the sandbox's own image (
- Images: used if the server has them; otherwise copied from this host (
docker save | ssh docker load), else pulled there, so no registry is needed. Sandbox images copied there are taggedgpulake-cache:<id>; theimage_cache(3) used last are kept, older ones removed unless a container uses them. - Shared servers: every 10 s (
observe_every) one SSH call reads all of the server's GPUs (memory, utilization, processes) and which container each process runs in. A GPU someone else uses is busy, exactly like a local one: not granted, and after they leave it settles first (pool.settle); someone else's process on a leased GPU is reported to the lease as contention. A server that stops answering has its GPUs held back until it answers again. Before creating a container, the GPUs are checked once more on the server. - Environment variables that look like credentials are not sent to the server (same filter as for rented
machines;
pass_envlists names to send anyway). - Validated live on a shared 10x L40 server: container ready in 3 s, a 1-GPU and a 2-GPU lease, another user's
process on a pool GPU making a 2-GPU request wait until it left (
tests/test_backends.py, opt-in withGPULAKE_TEST_SSH_HOST=user@host GPULAKE_TEST_SSH_GPUS=6,7).
Modal and Daytona notes:
- Modal:
token_fileholds themodal token set --token-id ... --token-secret ...line (or the two values); the credentials stay in memory, no Modal profile is written. Modal does not refuse a request for a GPU type that is busy, it queues it silently, so each type ingpu_typegetscreate_waitbefore the next is tried (seen live: no L4 for minutes, an A10G at once). The image is built on Modal before that wait starts (the 13 GB task image: 125 s the first time). Logs stream; spend uses Modal's list prices (usd_per_hourto override).image: sandboxworks: the read-only pull token goes to Modal as an ephemeral secret. - Daytona:
gpu_typeis one of its types (H100,H200,B200,L40S,RTX-4090,RTX-5090, ...); GPU sandboxes are ephemeral (deleted when stopped). Its SDK runs a command to completion without stdin, so data moves through files and a job's log is fetched every few seconds instead of followed. Private images come from registries set up in the Daytona dashboard, soimage: sandboxis not supported there. GPUs need GPU credits on the Daytona organization. Setusd_per_hourfor spend accounting.
How a lease on remote GPUs works:
- One lease never mixes backends: k GPUs on a remote backend are one machine with k GPUs. Pool order decides preference, so with local GPUs listed first, the cloud is used only when they are all taken.
- The machine is rented when the lease is granted, so it boots while the agent works (RunPod and Vast.ai take about 1–5 minutes; a job submitted meanwhile starts when it is up). A submitted job that has waited 20 s for a boot moves to a GPU that is ready now (a local one, or a machine already up for its agent) when one frees up and nobody queued wants it; the booting machine is kept warm for the agent or given back.
gpurun gpuslists each rented backend'stools(probed on its machines:nvcc,ncu,nsys, ...); an exit 127 there is explained (the machine runs another image). When the lease ends the machine stays warm forkeep_warm, for the same agent's next lease only: a machine is never handed to another agent, so no files or processes pass between agents. Then it is terminated.- A job runs in the backend's
image, not the sandbox's (unlessimage: sandbox). Its working directory (--cwd, default the sandbox's) is copied to the same path on the machine first: only what changed since the machine last got it (with--snapshotsubmitted earlier: as it was at submit time).sync_excludedefaults to.git,__pycache__,*.pyc,.venv,node_modules(onimage: sandbox:__pycache__,*.pyconly);sync_max_mbcaps one job's copy (2048; 16384 forssh). The files the job creates or changes there are copied back when it exits. Withimage: sandbox,--snapshotalso applies the sandbox's own filesystem changes, as on an owned server (above); on another image it can't (they are relative to the sandbox's image), and the job's response says so. The sandbox's environment variables are passed, except path-like ones that belong to the machine's own toolchain (PATH,LD_LIBRARY_PATH,HOME,CUDA_HOME, ...). Other paths and the sandbox's localhost are not shared, and the machine has its own internet access. The job's response tells the agent all this. - Logs stream into the same job log as a local job;
gpurun logs, signals, stop, expiry and restarts work the same (a restarted coordinator re-attaches to remote jobs and terminates machines it does not know). - Spend is estimated from each machine's hourly price. At
spend_limit_usd, or forfail_cooldown(5 min) after a machine fails to start, the backend's GPUs are not handed out.gpuctl statuslists each backend's machines, their state and the spend so far. - Validated with real Claude Code and Codex agents on RunPod and Vast.ai RTX 4090s (7 of 8 CUDA kernel tasks
solved, 28 agent jobs on rented GPUs, graders on a local GPU;
experiments/timeshare/RESULTS.md, E5). - Agents may choose, or leave it to the scheduler.
gpurun request|batch|submit --backend local|runpod|vast(comma-separated for several) and--gpu-type H200|4090|8.9|sm_89(a model name substring or a compute capability); MCPgpu_request/gpu_submittakebackendandgpu_type. Without them the scheduler picks, in pool order (local first). A choice no machine here can satisfy is denied at once with the options; one that is only busy waits for its GPUs.--backend localis how an agent gets full local semantics (shared volumes, its localhost) when it needs them.gpurun gpuslists each GPU's backend. - Run the sandbox's own image on rented machines (
image: sandbox): the image the agent's sandbox was created from is pushed toregistry(once per image) and the machine runs it, so its tools, libraries and glibc match the sandbox. Pushing uses this host's docker login orpush_username/push_password_file; providers pull withpull_username/pull_password_file, which should be a read-only token (GitHub: a classic token with onlyread:packages), since it is handed to the provider. Machines are reached over SSH, so before pushing, a thin layer addsopenssh-serverwhen the image lacks it (restoring the distro's package sources just for that, if the image stripped them, as anti-cheat task images do). The first push of a large image takes minutes; later machines only pull. Validated live: a 13 GB MLE-Bench kernel-task image, private on ghcr.io, pulled with aread:packagestoken by RunPod (machine ready in 80 s) and Vast.ai (172 s), running the task's ownbuild.shwith its CUTLASS / flashinfer headers. - Saved environments (
reuse_env, default on). What an agent built up on a machine (packages its jobs installed there, compiled extensions, JIT and model caches, its synced working directory) is not lost when the machine goes: it is saved, and the same agent's next machine on that backend starts from it, with nothing to copy for what is unchanged. Never another agent's (no files pass between agents), and only on the same base image.- Modal, Daytona, owned servers (
ssh) anddocker: when a used machine is given back (keep_warmover, or at the lease's end withkeep_warm: 0), its filesystem is saved first with the provider's own snapshot (Modalsnapshot_filesystem, keptenv_ttl; Daytonacreate_snapshot; on a server,docker committhere), then the machine is terminated (the save is billed as machine time). The next machine is created from the snapshot (Modal image id, Daytona snapshot name, server image). - RunPod, Vast.ai (no snapshots of a running machine): with
image: sandboxand aregistry, when a--snapshotjob finds at leastenv_push_min_mb(256) of sandbox changes the registry's environment lacks, they are baked into an image in the background (the sandbox image + those files + deletions, with the sshd layer) and pushed; the agent's next machine pulls it from the registry (near the machine) instead of this host uploading them to every machine, and only later changes are sent. Only the new layer is uploaded; later machines on the same host reuse it from the host's cache. - One environment per agent and backend: a newer save replaces the older one (deleted after the machine that
used it is gone).
env_ttl(24h) andenv_max(8 per backend) bound what is kept; afterenv_depth(16) saves on top of saves a machine starts from the plain image again (each save adds a layer). If a saved environment can't be had (expired, deleted), the machine starts from the plain image. - Validated live on an owned 10x L40 server: lease 1's job pip-installed a package on the machine and the workspace had a 50 MB file; at its end the container was committed (8.8 s). Lease 2 of the same agent got a machine from it in 6.1 s, the package was there, and nothing was copied (618 sandbox changes and the 50 MB file were already in place); another agent's lease got the plain image. Same test live on Modal (T4): save 2–3 s, the next machine from the snapshot ready in 3 s with the package there and nothing copied; on Daytona (RTX 4090): save 12–13 s, the sandbox from the snapshot keeps its GPU, ready in 12–22 s (8–32 s from the plain image), nothing copied. Another agent got the plain image on both; no snapshots or sandboxes were left behind.
- Modal, Daytona, owned servers (
- Logins never leave the sandbox with its filesystem.
--snapshotcopies and saved environments leave out where agents and tools keep credentials, whatever the config:~/.claude,~/.claude.json,~/.codex,~/.config/gpulake,~/.gpulake.yaml,~/.ssh,~/.netrc,~/.git-credentials,~/.docker,~/.aws,~/.azure,~/.config/gcloud,~/.config/gh,~/.huggingface,~/.cache/huggingface/token,~/.kaggle,~/.npmrc,~/.pypirc(for root and every user in/home).snapshot_excludeadds patterns; package caches (~/.cache/pip, apt lists) and Docker's per-container files are left out too. - Provider APIs are rate-limited (RunPod: per minute and per hour). Machine addresses are cached, boot polling
is every 15 s, and RunPod status / terminat
95F5
e / list fall back to its GraphQL API when REST is exhausted, so
a machine can always be given back.
image: sandbox registry: {repo: ghcr.io/me/gpulake-sandbox, pull_username: me, pull_password_file: ~/.gpulake/registry_pull}
- Agents may be limited to some backends (
policy.agents.<pattern>.backends: [runpod, vast]), e.g. to keep graders local.gpurun gpuslists only the GPUs the asking agent may use; give a backendgpu_name,compute_capandmemory_gibso agents know what to compile for before a machine has booted. - A machine that fails or does not come up within
boot_timeoutputs a submitted job back in the queue; the lease clock starts when the machine is up. Environment variables that look like credentials (TOKEN, KEY, SECRET, ...; the agent's own logins) are never sent to a rented machine (pass_envallows one). - Images: use the sandbox's base image when agents build binaries in their sandbox (glibc must match).
RunPod starts sshd itself for non-RunPod images; Vast.ai needs
start_sshd: truefor images its ssh setup does not handle (seen: Ubuntu 24.04 CUDA images).setup:runs a command once per machine. - Each backend gets its own SSH key (
<db dir>/keys/<backend>_ed25519, created on first start); RunPod receives it asPUBLIC_KEY(RunPod's images start sshd with it), Vast.ai attaches it to the instance.
Fault tolerance
No backend is 100% reliable: rented machines fail to start, get preempted, hang, or vanish; provider APIs error and rate-limit; terminate calls fail; local GPUs fall off the bus. What the coordinator does:
| failure | what happens |
|---|---|
| a provider API error (5xx, timeout, connection) while creating a machine | retried at once (twice, 10 s / 30 s apart); "no capacity" is not retried there, other backends are used |
| a backend's machines keep failing | circuit breaker: it sits out fail_cooldown (5 min; lost_cooldown, 1 min, when the last failure was a machine lost while running), doubling with each failure in a row up to max_fail_cooldown (1 h); then one machine is tried, and a success resets it. gpurun gpus (unavailable), waiting_for and gpuctl status (health) say so |
a machine never comes up (boot_timeout), or can't be had |
a submitted job goes back to the queue (its place kept); a job run on a lease gets the same lease on other GPUs. A lease does not expire while its job waits for a machine to start |
a machine is lost mid-job: gone at the provider, or unreachable for lost_after (3 min) |
the machine is given back and counted against its backend; a submitted job is rerun from the start (other GPUs first, else a new machine on the same backend) (runner.retry_lost, default 2; its view shows attempts and rerun_because); a lease gets other GPUs under the same id, and a command run on it meanwhile waits for them |
| a machine vanishes while idle or between jobs | health checks (health_every, 60 s) notice; same as above |
| a submitted job waits for a slow boot while another GPU is free | it moves there (see GPU backends) |
| terminate fails | retried, then every minute (also after a restart; the state file keeps the list) until the provider confirms; health.unterminated_machines lists them |
| a machine leaks (a create that timed out but happened) | the orphan sweep (sweep_every, 10 min) terminates machines with this backend's name prefix that it does not know |
a local GPU disappears from the driver, or fails to start a job container (nvidia-container-cli, NVML errors) |
not scheduled while missing / for runner.gpu_fault_cooldown (10 min); the job is rerun on another GPU; waiting_for says why |
| the coordinator restarts | leases, jobs and machines are in SQLite and the backends' state files; jobs are re-attached, failure counts and cool-downs kept |
Tests: tests/test_faults.py injects each of these. Live: a Modal sandbox terminated under a running job (detected
in 4 s, the job rerun on RunPod, the agent's one --wait-end call returned exit 0 with attempts: 2), a RunPod pod
deleted under an interactive lease (detected in 10 s), and a Modal sandbox killed under another lease (the agent's
next command on the same lease waited and ran on RunPod).
Admin: gpuctl
gpuctl status # per-GPU pool/lease/busy state, open leases, running jobs
gpuctl pool add 3 ; gpuctl pool remove 5 --now
gpuctl revoke L12 --reason "maintenance"
gpuctl token create --user alice --agent a1 [--container NAME | --host] [--ttl 7d] [-q]
gpuctl token revoke --agent a1 ; gpuctl token list
gpuctl reload # re-read the policy section
gpuctl report --since 2h [--user U] # per GPU: % held by leases / running jobs / held but idle, SM util;
# per agent: leases, jobs, GPU-s held vs used, queue waitsgpuctl report uses the jobs and leases ledger plus SM-utilization samples of every pool GPU, taken
every server.sample_every (default 5 s, kept server.sample_keep, default 3 d). "Held but idle" is time a
lease kept a GPU from everyone else while none of its jobs ran.
Tests and the stress test
.venv/bin/pytest tests/test_core.py # scheduler/policy/enforcement, fake clock
GPULAKE_IT=1 GPULAKE_IT_GPUS=4,5 .venv/bin/pytest -s tests/test_integration.py # real Docker + GPUs
.venv/bin/pytest tests/test_integrations.py # Claude Code / Codex templates + installer
GPULAKE_HARBOR_PYTHON=/path/to/harbor/.venv/bin/python [GPULAKE_HARBOR_E2E=1] \
.venv/bin/pytest tests/test_harbor.py # Harbor environment (+ oracle job end to end).venv/bin/python tests/stress/stress.py -c ~/.gpulake.yaml --out /some/dir \
--sandboxes 16 --networks 4 --duration 900 --load-agents 100 --load-iters 30 [--light] [--no-faults]The run has these parts:
- API load: host-token agents hammer request, status and release calls.
- Agents: sandboxes on shared bridge networks run
tests/stress/agent.py. Each does a random mix of:- real PyTorch jobs on 1 or 2 GPUs;
- detached servers reached over the sandbox's localhost;
- Ctrl-C, SIGTERM and SIGKILL of the client;
batchruns and MCP calls;- attempts to touch other agents' leases;
- jobs that ignore SIGTERM;
- the expiry warning and pre-expiry signal path.
- Injected faults: cross-agent job access, token theft,
systemctl restart, SIGKILL of the daemon, and a sandbox removed while it holds GPUs. - Monitor: a host-side monitor checks every second that:
- no GPU is in two leases;
- each job container has only its own lease's GPUs;
- no job container outlives its lease by more than
stop_timeout; - no GPU is handed to a new lease while an old job is still alive;
- every process on a pool GPU belongs to the job of the lease that holds that GPU.
- Final checks: no leaked leases or containers, and the ledger's lease intervals never
overlap on any GPU. Everything is written to
report.json.
--light makes jobs only check GPU visibility with nvidia-smi and sleep, without creating a
CUDA context. Use it with a test instance whose pool.respect_foreign is false when the pool GPUs
are busy with other people's work.
- Fair-share priority (decaying recent usage) and topology-aware placement. GPUs are currently picked in pool order.
- Preemption and fractional GPUs (MPS / MIG).
- Splitting one lease across several machines (a lease's GPUs are on one machine).
- A job on a remote machine does not share the sandbox's network: a server it starts is reachable on that machine,
not on the agent's
localhost.
- Technical report: the design, the optimizations, and case studies with real agents.
- Blog post: the story and the main results.
- Agent guide: what the models read; leases, jobs, rules, recipes and errors.
- Experiments: every run behind the numbers above, with scripts.
GPULake is released under the MIT License.