Connect once
Everything is in thedrkm module. Inside an agent sandbox no connection step is needed. From anywhere else, connect() sends the job and fleet calls to an outpost’s HTTPS API. The outpost is the address you pass, else $DRKM_URL, else the active drkm console profile. The credential is token (an API key an administrator minted under Settings → Keys → API keys, or an ID token), else session (a password sign-in’s cookie), else $DRKM_TOKEN, else what drkm console login stored. HTTPS only, except localhost.
Connect and inspect
After connect() the SDK serves submit, estimate, job, jobs, wait, cancel, answer, results, rows, the Dataset verbs and outposts. Agent tasks, sources and model calls stay inside a sandbox and raise BridgeError elsewhere; drkm.tools exists only inside one.
Records, workers and bundles
A job runs one operation over input records. Each record is{"id", "data", "files"}: an ID that is unique within the job, any JSON as data, and up to 16 workspace-relative file paths. A job holds at most 100,000 records.
package() describes a script operation: the entrypoint module.py:function, the workspace files sealed with the job (the entrypoint module among them, 64 at most), the models and sources it needs and whether it is safe to replay. The platform calls run(records, context) once with every record, as one partition, and the return value is the job’s output. Per-row Python spread over the fleet is a Broom sweep, in drkm.broom.
Inside an attempt, context.read(path) returns a staged input file as bytes, context.models["alias"] a model you declared, and context.sources["alias"] a declared read-only source.
Worker contracts
Submit, wait, collect
submit() returns the job ID at once. Its keyword arguments:
name: What operators read in the job list, at most 120 characters. Say what it does and where.inputs: The records inline, orinputs_filenaming a workspace JSON file when the manifest is large.key: Makes a retry idempotent: the same key with the same work returns the same job; the same key with different work is refused.limits: Default first, then the ceiling:partition_size16 (up to 512; a script is always one partition),max_attempts3 (up to 10),attempt_timeout_s600 (up to 86400),concurrency64 (up to 256).allowed,preferred: A hard limit and a soft hint, as outpost IDs fromoutposts().preferred=["self"]prefers the submitting outpost.
wait() polls until the job settles and returns its snapshot: state, coverage (expected, completed, failed, running, pending), error, blocked. results() writes the manifest and every accepted partition under jobs/<id>/; rows() reads them back as {"record_id", "output"} in partition order; a script’s one row has a null record_id. Until a job settles, rows() holds only the partitions accepted so far.
Reopen, follow, cancel
A job for an agent is a job too: submit(drkm.agent_task(“count the ships”)). When it asks a question the job enters input_required; answer it with wait(job_id, on_input=…) or answer(job_id, input_id, text).
The dataset interface
A served detector over many images reads like a dataframe pipeline: describe every input and the model in one chain, and the scheduler decides partitions, placement and retries.parallelize() takes inline records and read.json() a workspace file of them. A dataset has one stage, .predict(model, conf=..., classes=...), and each record names its one image in files. .explain() answers what the scheduler would do and runs nothing; .submit() returns a Job. Both work inside a sandbox and after connect().
Run this example from your own Python environment after installing the SDK. Inside an agent sandbox, omit connect(); the sandbox already supplies a bridge.
A detector over records
Inside a sandbox: tasks, tools, sources
Code the agent runs on its computer can do more than submit jobs.task() pushes a prompt to this outpost’s agent, to a named peer from outposts(), or to the operator-configured remote, and returns a handle; gather() waits for one or several and returns their output. Configured connections expose typed functions under drkm.tools, generated from the outpost’s current settings; the host performs each call with the turn’s authority, and the program never holds a credential or an address. drkm.sources(alias).read(...) reads bounded data from a declared source.
The same calls are available from bash as the sandbox’s drkm command, printed as JSON. They work in a background run too, for as long as it runs.
Tools and tasks
Errors you will meet
BridgeErrorcarries the broker’s reason verbatim: a refusal, a failed task, a lost connection, or an HTTP error from the outpost.BridgeUnavailablemeans this machine has no bridge: outside a sandbox,connect()found no outpost or no credential, and the message names the fix. Inside one, the exec or background run that started the process has ended.- not signed in after
connect(): the terminal stored its credential in the OS keyring and the script’s environment lacks the keyring package. Install it withpython -m pip install keyring. For automation without a keyring, inject a token from your secret manager intoDRKM_TOKENat runtime. - runs only inside a sandbox after
connect(): agent tasks, tools, sources and models need a sandbox. From a laptop, submit a job instead. - Missing rows: the job has not settled, so
rows()holds only the partitions accepted so far. Callwait()first. - A 409 on submit: the key was used for different work.
import drkm always succeeds, so help(drkm) answers everywhere.