All articles

Give OpenAI Codex a GPU with the Lium CLI

Let the Codex CLI rent a Lium GPU, run your code on it and clean up after itself, using an AGENTS.md rules block, a scoped API key with a daily budget, and automatic pod removal.
Lium team3 min read
codex
ai-agents
cli
Codex runs shell commands in your project, so the lium CLI is enough for it to rent a GPU and use it. Codex reads its project rules from AGENTS.md. Put the Lium rules there, give it a key with a budget, and Codex can benchmark, train or test on real GPUs, then remove the pod when it is done.
We did not run Codex itself for this post. The lium commands below are the ones we tested against lium.io on 15 Oct 2026 with CLI 0.16.1 in Give Claude Code a GPU in 60 seconds. In that run a single RTX 5070 Ti pod was ready 26 seconds after lium up, and the run cost $0.006. For Codex, only the rules file is different.

1. A key for the agent, with a budget

The quickest key is ADD NEW + on lium.io/api-keys: it can read, rent and manage pods but never touch billing. To add a budget the server enforces, create the key with POST /keys from your signed-in session instead (an email-and-password account gets the session token from /users/login). This key stops at $5 per UTC day:
bash
API=https://lium.io/api
JWT=$(curl -s $API/users/login -H "Content-Type: application/json" \
  -d '{"email": "you@example.com", "password": "…"}' | jq -r .token)
curl -s $API/keys -H "Authorization: Bearer $JWT" -H "Content-Type: application/json" \
  -d '{"name": "codex", "scopes": ["read", "rent", "manage"], "daily_budget_usd": 5, "pod_visibility": "own"}'
"pod_visibility": "own" means Codex sees and controls only the pods it rented, never the rest of your account.

2. Install the CLI where Codex runs

bash
pip install lium.io
export LIUM_API_KEY=sk_...
lium whoami
Codex's sandbox must allow network access for lium to reach lium.io and the pod. Enable it for the session, or run the commands in a mode that permits network calls.

3. The rules, in AGENTS.md

markdown
## GPU compute (Lium)
 
Rent GPUs with the `lium` CLI (key in LIUM_API_KEY; never print it).
- Pick a node: `lium ls --count 1 --format json` (cheapest first) unless a GPU type is requested.
- Rent with a name and a deadline: `lium up <huid> --name <name> --ttl 1h -y --json`. Never omit --ttl.
- Run: `lium exec <name> "<command>"`; long jobs: `lium exec <name> -d "<command>"`.
- Results: `lium scp <name> <remote-file> <local-dir> -d`.
- Always finish with `lium rm <name> -y` and `lium ps`, also after a failure.
- On API_KEY_BUDGET_EXCEEDED, stop and report.

4. A typical session

An illustrative session: asked to "run the test suite on a GPU and report failures", Codex would run commands like these (the repository URL is a placeholder):
bash
NODE=$(lium ls --count 1 --format json | jq -r '.[0].huid')
lium up "$NODE" --name codex-gpu --ttl 1h -y --json
lium exec codex-gpu "nvidia-smi --query-gpu=name,memory.total --format=csv"
lium exec codex-gpu "cd /root && git clone https://github.com/you/project && cd project && pip install -e . && pytest -x -q"
lium rm codex-gpu -y && lium ps
lium exec returns the remote command's exit code, so Codex can tell a failing test run from a passing one. --json keeps lium up output machine-readable: progress goes to stderr and the ready pod goes to stdout.

Why Lium for coding agents

  • Guardrails on the server. The key's scopes, its daily budget (a rent past it is refused with 402 API_KEY_BUDGET_EXCEEDED) and --ttl removal are all enforced by Lium, not by the agent's own discipline.
  • Per-second billing. A short GPU test costs cents, and nothing is charged once the pod is removed.
  • A real machine. Every pod has root access and its own Docker daemon, so the agent can build and run containers inside it.
Run it on Lium
Browse GPUs