Docs · SDK
SDK
One client for Python and TypeScript. The same six verbs as the console: create, run, files, reset, stop, and fleets.
Install and authenticate
pip install kalworks
export KALWORKS_API_KEY=kw_live_…What the SDK promises
- Compute can’t be left running by accident
- Sandboxes are context managers. Leaving the block, or an exception, stops them. Every sandbox also has a maximum runtime.
- Retries never double up
- Every create call sends an idempotency key. Retrying after a timeout returns the same sandbox, not a second one.
- Results say what they mean
- run() returns exit code, output and cost. It never claims an eval passed. Your tests report outcomes.
- Errors tell you what to do next
- Each error has a code, whether it’s retryable, and a request ID for support.
Sandboxes
import kalworks
with kalworks.sandboxes.create(
workload="rl-v1", # pins environment digest + policy
machine="standard-2",
shut_down_after_min=10,
) as sb:
sb.wait_ready() # queued and provisioning are free
r = sb.run(["pytest", "-q"], timeout_s=300)
print(r.exit_code, r.stdout[-2000:])
sb.reset() # back to the pinned environment, same machine
# leaving the block stops the sandbox; billing ends on confirmed releaseFiles and artifacts
sb.files.write("/workspace/task.json", json.dumps(task))
sb.run(["python", "solve.py"])
for a in sb.artifacts.list("/workspace/out"): # checksum + size included
a.download(f"./out/{a.name}")Fleets
Your tests report each task’s outcome. Kalworks reports what ran and where infrastructure failed.
Python
fleet = kalworks.fleets.create(
name="eval-batch-043", workload="rl-v1", slots=48,
if_partial="start", retry="infrastructure_only", budget_usd=20,
labels={"suite": "terminal-bench", "commit": "a91f2c"},
)
for task in fleet.tasks(tasks): # one sandbox per task, reused after reset
r = task.run(["bash", "run_task.sh"])
task.report("passed" if grade(r) else "failed")
summary = fleet.wait()
print(summary.passed, summary.safe_to_retry, summary.cost_per_passed)
fleet.retry(summary.safe_to_retry) # adds attempts, not tasksErrors
Python
from kalworks import errors
try:
sb = kalworks.sandboxes.create(workload="rl-v1", machine="highmem-8")
except errors.CapacityUnavailable as e:
print(e.retryable, e.retry_after_s, e.request_id)
except errors.QuotaExceeded as e:
print(e.message) # "8 of 8 High memory 8 slots in use. Request more on Limits."