Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .claude-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "drums",
"description": "Isolated desktops for computer-use agents: start a computer from a template, act with GUI, shell and files, verify against a task checker, fork and reset, and read run results, all through the Drums MCP server.",
"version": "0.3.0",
"version": "0.4.0",
"author": { "name": "Drums Labs" }
}
2 changes: 1 addition & 1 deletion .github/scripts/pip-audit.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
# Dependency audit (A-40): install the package into a fresh venv the way CI does, freeze what got installed, and run
# Dependency audit: install the package into a fresh venv the way CI does, freeze what got installed, and run
# pip-audit on exactly that set. Fails on any known vulnerability that is not in the allowlist (.pip-audit-ignore).
#
# .github/scripts/pip-audit.sh PIP_INSTALL_ARGS... e.g. .github/scripts/pip-audit.sh '.[test]'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
python -m build
python -m twine check --strict dist/*

# A-40: the SDK has no runtime dependencies; the audited set is what CI installs to build and check it (pip, build,
# the SDK has no runtime dependencies; the audited set is what CI installs to build and check it (pip, build,
# twine and their dependencies). Fails on any advisory not in .pip-audit-ignore.
audit:
name: pip-audit
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dependency-audit.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Weekly dependency audit (A-40): the same pip-audit as CI, on a schedule, against today's advisory database and today's
# Weekly dependency audit: the same pip-audit as CI, on a schedule, against today's advisory database and today's
# resolution of the declared ranges. On failure it opens one issue labelled "dependencies", or comments on the one that
# is already open; it never closes an issue (a person does, after the fix lands).
name: dependency-audit
Expand Down
2 changes: 1 addition & 1 deletion .pip-audit-ignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Accepted pip-audit advisories (A-40). One per line: <advisory id> <review-by YYYY-MM-DD> <reason>
# Accepted pip-audit advisories. One per line: <advisory id> <review-by YYYY-MM-DD> <reason>
# An entry past its review date fails the audit. Empty: nothing is accepted today.
22 changes: 11 additions & 11 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ SDK version was built against is noted where it matters.

## 0.4.0 - 2026-11-18

Post-D1 fixes for training clients (audit 2026-11-16), integrated in one release. Minor version: new API and one
Fixes for training clients, from our first 128-desktop training run, integrated in one release. Minor version: new API and one
behaviour change (429 replies are retried, with an off switch); nothing is removed and no dependency is added. Every
0.3 call keeps its signature and meaning. Built against drumsd 0.4.2 and the gateway routes of Drums-Labs/drums #41
(trainer runs), #43 (desktop tokens), #46 (task-set tasks) and #49 (`GET /v1/limits`); against an older gateway each
feature falls back as described below.

### Changed

- **429 replies are retried on every call** (A-29, #11). A 429 (the gateway's per-key rate limit, or no capacity
- **429 replies are retried on every call** (#11). A 429 (the gateway's per-key rate limit, or no capacity
right now: nothing was started) is retried for every method, step, screenshot, verify, create and fork included,
waiting at least the reply's `Retry-After` (seconds or an HTTP date), with jittered exponential backoff, for at
most 60 s of waiting per call (or 20 retries). `drums.RetryPolicy(max_wait_s, max_attempts, base_s, cap_s, jitter)`
Expand All @@ -23,7 +23,7 @@ feature falls back as described below.

### Added

- **Desktop tokens** (A-30, #14; design note "control plane out of the data path", 3.1). `drums.connect(url, key)`
- **Desktop tokens** (#14). `drums.connect(url, key)`
keeps its signature. With a Drums API key (`drums_sk_...`) the client asks the gateway once how it authenticates
(`GET <url>/auth`, no credential). When the gateway says `token` or `both`, the key is sent once to the console's
token URL (https, or loopback http; the same transport and redirect rules as every other request) and the gateway
Expand All @@ -36,11 +36,11 @@ feature falls back as described below.
gateway's mode was known (the discovery request got no answer) is retried once after a 401. A drumsd token, or a
gateway in `api_key` mode, works exactly as before. Neither the key nor the token appears in a repr
(`repr(client)` shows the auth kind only) or an error message.
- **macOS certificates** (A-07, #11). When the system store cannot verify the gateway or the console and `certifi`
- **macOS certificates** (#11). When the system store cannot verify the gateway or the console and `certifi`
is installed, the client switches to certifi's CA bundle once (for both) and prints one line naming the server;
without certifi it raises the new `CertificateError` (a `DaemonUnavailable`) with the fix
(`Install Certificates.command` or `pip install certifi`). No new dependency.
- **Run object** (A-36, #12, matching the gateway's trainer runs). `with client.run(name, kind="training",
- **Run object** (#12, matching the gateway's trainer runs). `with client.run(name, kind="training",
task_set=..., config=..., desktops_provisioned=N) as run:` opens a run (`POST /v1/runs`),
`run.step(step, reward=, zero_advantage_share=, rollouts=, desktops_busy=, desktops_provisioned=)` buffers points
sent at most once per 30 s (`PATCH /v1/runs/{id}`), and the block's end closes it (`POST /v1/runs/{id}/close`:
Expand All @@ -55,22 +55,22 @@ feature falls back as described below.
`client.run(<run uuid>)` alone still returns the run's record; `get_run` and `open_run` are the explicit names.
- **`drums preflight`** (#13). `drums preflight --desktops N --hours H [--model-gpus 2:6] [--task-set ID] [--json]`
and `drums.preflight(...)`: gateway and console health, key validity, expiry and scopes, host capacity and
admission, rate limit (N x 0.5 requests/s, the D1 rule, `REQUESTS_PER_DESKTOP_S`), live-desktop quota, spend cap at
admission, rate limit (N x 0.5 requests/s, a rule of thumb from our training runs, `REQUESTS_PER_DESKTOP_S`), live-desktop quota, spend cap at
the projected desktop-hour cost, and the task set's registration and validation. A pass/fail table with a fix and a
console link per row; exit 1 on a failure (`--strict`: also on a warning or a row it could not check). Works in
desktop-token mode: the exchange runs first, so a console that cannot issue a token is an auth failure (a `both`
gateway on the key alone is a warning), and the console row defaults to the token URL's origin. Rate limit, quota,
spend cap, price and host admission come from `GET /v1/limits` (scope `usage:read`, Drums-Labs/drums#49); a
spend cap, price and host admission come from `GET /v1/limits` (scope `usage:read`); a
gateway without it gets "not checked" on those rows.
- **MCP custom tasks** (A-08, A-09, #15). `create_computer` and `load_task` take `task_set_id` + `task_id` (a task of
- **MCP custom tasks** (#15). `create_computer` and `load_task` take `task_set_id` + `task_id` (a task of
a registered set) besides `task` and `task_id`; a task document sent as a JSON string is accepted; new tools
`list_task_sets` and `get_task_set` (36 tools, the gateway's tools.json); `verify` on a computer with no task says
so. Needs the gateway route `GET /v1/task-sets/{id}/tasks/{task_id}` (Drums-Labs/drums#46).
so. Needs the gateway route `GET /v1/task-sets/{id}/tasks/{task_id}`.

### CI

- A `pip-audit` job on what CI installs, with an allowlist whose entries expire, and a weekly audit that opens an
issue on failure (A-40, #10).
issue on failure (#10).
- The test matrix (3.9 to 3.13) runs on `ubuntu-24.04`: `ubuntu-latest` is 26.04, which has no Python 3.9 build.

## 0.3.0 - 2026-11-12
Expand Down Expand Up @@ -105,7 +105,7 @@ this release adds the local server and the client methods for the new gateway ro

## 0.2.5 - first release on PyPI

The first version published on PyPI, as `drums-sdk` (`pip install drums-sdk`; the import name stays `drums`). Versions 0.2.0 to 0.2.4 shipped as wheels sent with invites.
The first version published on PyPI, as `drums-sdk` (`pip install drums-sdk`; the import name stays `drums`). Versions 0.2.0 to 0.2.4 were not published.
Everything below in the 0.2.x entries is included.

Packaging and release:
Expand Down
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ task's checker. Every episode carries a validity verdict, so a score from a brok

This repository is the Python client for that runtime and the `drums` command. The package on PyPI is `drums-sdk`;
the import name is `drums`. It uses only the standard library and supports Python 3.9 and later. It talks to Drums
Cloud (`https://beta.drums.run/gw`) or to a self-hosted `drumsd` over the same HTTP API.
Cloud (`https://beta.drums.run/gw`, the gateway for invited teams) or to a `drumsd` you run yourself, over the same HTTP
API.

## Install

Expand All @@ -48,7 +49,11 @@ pip install drums-sdk

## Quickstart

Sign in at [console.drums.run](https://console.drums.run), open **API Keys** and create a key. It starts with
> **Drums Cloud is invite-only until January 2027.** [Request access](https://console.drums.run/request-access). Without an invite you can still install
> the SDK, read the API below and run the test suite (`python -m unittest`, no account needed); the tests run every
> call against a local fake server.

With an invite, sign in at [console.drums.run](https://console.drums.run), open **API Keys** and create a key. It starts with
`drums_sk_` and is shown once. Then, in a terminal:

```bash
Expand Down Expand Up @@ -106,7 +111,7 @@ print(report.table()); assert report.ok
| auth | the key is accepted, not revoked, and does not expire before the run ends; on a gateway in desktop-token mode, the console issued a token for it (`both` mode on the key alone is a warning) |
| scopes | `computers:read` and `computers:write` (required; `computers:write` also opens runs); `usage:read` (warned: `GET /v1/limits` needs it) |
| host capacity, admission | the bound host has N free desktops, drumsd is ok, the host takes creates and no image checkpoint is stale |
| rate limit | the per-key limit is at least N x 0.5 requests/s with a burst of N (the D1 rule: about 0.5 requests per second per active desktop, `drums._preflight.REQUESTS_PER_DESKTOP_S`) |
| rate limit | the per-key limit is at least N x 0.5 requests/s with a burst of N (a rule of thumb from our own training runs: about 0.5 requests per second per active desktop, `drums._preflight.REQUESTS_PER_DESKTOP_S`) |
| quota | the workspace's live-desktop limit leaves room for N |
| spend cap | spent + N x H x the desktop-hour price stays under the cap |
| task set | registered for the workspace and validated on a host (oracle accepted, none rejected) |
Expand Down Expand Up @@ -264,7 +269,7 @@ the run (task set, config hash, steps, reward, zero-advantage share, rollouts, d
of anonymous computers:

```python
with client.run("qwen27b-d2", kind="training", task_set=task_set_id, config=cfg, desktops_provisioned=128) as run:
with client.run("my-grpo-run", kind="training", task_set=task_set_id, config=cfg, desktops_provisioned=128) as run:
for step in range(num_steps):
... # your rollouts and optimizer step
run.step(step, reward=mean_reward, zero_advantage_share=zero_adv, rollouts=n, desktops_busy=busy)
Expand Down
4 changes: 2 additions & 2 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

| Version | Supported |
|---|---|
| 0.3.x | yes |
| 0.2.x | security fixes only, until 0.4.0 is released |
| 0.4.x | yes |
| 0.3.x | security fixes only |
| earlier | no |

The SDK uses only the Python standard library and has no runtime dependencies. Upgrade with `pip install -U drums-sdk`.
Expand Down
14 changes: 13 additions & 1 deletion drums/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@
from .runs import Run, RunNotSupported

__version__ = "0.4.0"
DEFAULT_URL = os.environ.get("DRUMS_URL") or os.environ.get("DRUMSD_URL") or "http://127.0.0.1:7070"
LOCAL_URL = "http://127.0.0.1:7070"
DEFAULT_URL = os.environ.get("DRUMS_URL") or os.environ.get("DRUMSD_URL") or LOCAL_URL
_NO_SERVER_HINT = ("no server answers at " + LOCAL_URL + " and DRUMS_URL is not set. Set DRUMS_URL to your gateway "
"(Drums Cloud: https://beta.drums.run/gw, invite-only until January 2027, request access at "
"https://console.drums.run/request-access) or start a drumsd on this machine")
DEFAULT_IMAGE = "osworld-ubuntu"

__all__ = ["ActionFailed", "connect", "Client", "Env", "Reward", "Observation", "StepResult", "State", "ForkResult", "env", "__version__",
Expand Down Expand Up @@ -473,6 +477,10 @@ def __init__(self, url: str = DEFAULT_URL, token: str | None = None, timeout: fl
self._cred = _Credentials(self.token) # API key -> desktop token exchange when the gateway asks for it
self._owned: dict[str, None] = {} # ids of envs this client created and has not closed (insertion order)
self._owned_lock = threading.Lock()
# Nobody chose a server: the URL is the loopback default and no env var named one. If nothing answers there on
# the very first request, say so at once instead of retrying a daemon the user may not have.
self._implicit_local = self.url == LOCAL_URL and not (os.environ.get("DRUMS_URL") or os.environ.get("DRUMSD_URL"))
self._answered = False
self._runs: list = [] # open Run objects, innermost last: creates carry its label
self.close_on_exit = close_on_exit
if close_on_exit:
Expand Down Expand Up @@ -591,8 +599,10 @@ def call(self, method: str, path: str, body=None, raw: bool = False, timeout: fl
try:
with self._opener.open(req, timeout=timeout or self.timeout) as r:
b = r.read()
self._answered = True
return b if raw else json.loads(b or b"null")
except urllib.error.HTTPError as e:
self._answered = True
text = e.read().decode(errors="replace")
try:
body_j = json.loads(text)
Expand Down Expand Up @@ -637,6 +647,8 @@ def call(self, method: str, path: str, body=None, raw: bool = False, timeout: fl
continue
raise CertificateError(_origin_text(self.url), str(getattr(e, "reason", e)),
"certifi's bundle could not verify it either" if self._certifi else _CERT_HINT) from None
if self._implicit_local and not self._answered and isinstance(getattr(e, "reason", e), ConnectionRefusedError):
raise DaemonUnavailable(0, _NO_SERVER_HINT) from None
if time.monotonic() >= deadline:
what = "the outcome is unknown; call env.refresh()" if method != "GET" else f"retried for {self.retry_s:.0f} s"
raise DaemonUnavailable(0, f"drumsd at {self.url} unreachable on {method} {path} ({what}): {getattr(e, 'reason', e)}") from None
Expand Down
16 changes: 8 additions & 8 deletions drums/_preflight.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""`drums preflight` / `drums.preflight(...)`: before any GPU is paid for, check that the gateway, the key and the
workspace can carry N desktops for H hours. Every block of the D1 run (rate limit, spend cap, live-desktop quota,
workspace can carry N desktops for H hours. Every block we hit in our own 128-desktop training run (rate limit, spend cap, live-desktop quota,
host capacity, control-plane health, a task set nobody had validated) would have shown up here.

drums preflight --desktops 128 --hours 3 --task-set 0b5c2a52-... [--model-gpus 2:6] [--json]
Expand All @@ -23,7 +23,7 @@
spend cap spent this period + N x H x the desktop-hour price <= the cap
task set (with --task-set) registered for this workspace, and validated (oracle accepted, none rejected)

The rate limit, quota, spend cap and price come from `GET /v1/limits` (scope usage:read; Drums-Labs/drums#49, shape
The rate limit, quota, spend cap and price come from `GET /v1/limits` (scope usage:read; shape
in `_limits_view`). On a gateway that does not serve it yet, those rows say "not checked" and why, and
`--desktop-hour-usd` supplies the price for the projection. A row that could not be checked never fails the
preflight; `--strict` does.
Expand All @@ -40,7 +40,7 @@

from .errors import AuthError, DrumsError, NotFound

#: D1 rule of thumb (2026-11-16, 128 desktops on Qwen3.5-27B): each ACTIVE desktop costs about one action and one
#: Rule of thumb from our 128-desktop GRPO run on Qwen3.5-27B (2026-11-16): each ACTIVE desktop costs about one action and one
#: screenshot per turn every few seconds through the gateway, about 0.5 requests per second (128 desktops needed about
#: 60 req/s). A run of N desktops needs a per-key rate of at least N x this.
REQUESTS_PER_DESKTOP_S = 0.5
Expand All @@ -50,7 +50,7 @@
#: The gateway's default per-key limit (RATE_LIMIT_PER_S / RATE_LIMIT_BURST unset): a pilot setting.
DEFAULT_RATE_PER_S, DEFAULT_RATE_BURST = 20, 60
REQUIRED_SCOPES = ("computers:read", "computers:write")
#: runs:write is not wanted: the gateway opens trainer runs with computers:write too (Drums-Labs/drums#41)
#: runs:write is not wanted: the gateway opens trainer runs with computers:write too
WANTED_SCOPES = {"usage:read": "usage and cost reads (and GET /v1/limits, so the quota and spend rows) are refused"}
#: /v1/health slower than this is a warning, ten times slower a failure (the 2026-11-16 outage answered in 10 to 90 s)
HEALTH_SLOW_S = 2.0
Expand Down Expand Up @@ -147,7 +147,7 @@ def _num(d, *keys):


def _limits_view(doc) -> dict:
"""The fields preflight reads from `GET /v1/limits` (served by Drums-Labs/drums#49; any of them may be missing,
"""The fields preflight reads from `GET /v1/limits` (any of them may be missing,
and the gateway's extra fields are ignored):

{"workspace": {"max_live_computers", "live_computers", "max_spend_usd", "spent_usd", "period_end",
Expand Down Expand Up @@ -272,7 +272,7 @@ def preflight(desktops: int, hours: float, *, model_gpus=None, task_set: str | N
add(Check("gateway", PASS, f"{client.url} answers (auth mode {token_mode or 'token'})"))
if isinstance(token_err, AuthError):
add(Check("auth", FAIL, f"the console refused the key when asked for a desktop token: {token_err.message}",
"create a key (or check DRUMS_TOKEN has no stray space or newline)", links.page("api-keys", "API keys")))
"create a key (or check DRUMS_TOKEN has no stray space or newline); no account? Drums Cloud is invite-only until January 2027: request access at https://console.drums.run/request-access", links.page("api-keys", "API keys")))
else:
add(Check("auth", FAIL, f"no desktop token: {token_err.message}",
"this gateway takes desktop tokens only; the console must answer to issue one: wait, or report it",
Expand All @@ -295,7 +295,7 @@ def preflight(desktops: int, hours: float, *, model_gpus=None, task_set: str | N
except AuthError as e:
add(Check("gateway", PASS, f"{client.url} answers"))
add(Check("auth", FAIL, f"the key was refused: {e.message}",
"create a key (or check DRUMS_TOKEN has no stray space or newline)", links.page("api-keys", "API keys")))
"create a key (or check DRUMS_TOKEN has no stray space or newline); no account? Drums Cloud is invite-only until January 2027: request access at https://console.drums.run/request-access", links.page("api-keys", "API keys")))
return _finish(desktops, hours, checks, need, gpus, gpu_hour_usd, check_console, console, timeout)
except DrumsError as e:
if e.status == 403:
Expand Down Expand Up @@ -518,7 +518,7 @@ def _finish(desktops, hours, checks, need, gpus, gpu_hour_usd, check_console, co
gpu_usd = gpus["total"] * hours * float(gpu_hour_usd)
need["projected_gpu_usd"] = round(gpu_usd, 2)
detail += f"; projected {gpu_usd:,.2f} USD at {gpu_hour_usd:g} USD per GPU-hour"
detail += (". In D1 (Qwen3.5-27B, 2 inference + 6 trainer GPUs) the trainer kept 36 to 47 of 128 desktops in "
detail += (". In our 128-desktop run (Qwen3.5-27B, 2 inference + 6 trainer GPUs) the trainer kept 36 to 47 of 128 desktops in "
"flight; size N to what your trainer keeps in flight")
checks.append(Check("model GPUs", INFO, detail))
return PreflightReport(desktops, hours, checks, need)
Expand Down
Loading
Loading