Quickstart
In etwa fünf Minuten erstellen Sie eine Sandbox, führen einen Befehl aus, schreiben und lesen eine Datei und löschen sie wieder. Die Beispiele nutzen nur die Standardwerkzeuge der jeweiligen Sprache.
1. API-Schlüssel besorgen
- Registrieren und die E-Mail-Adresse bestätigen. Im Early Access können neue Registrierungen auf eine Warteliste kommen.
- Im Dashboard unter API-Schlüssel einen Schlüssel erstellen. Schlüssel sehen aus wie
kbn_t…und werden nur einmal angezeigt. - Exportieren:
export KABIN_API_KEY=kbn_...
Die Beispiele lesen KABIN_API_KEY und optional KABIN_API_URL (Standard https://api.kabin.dev). Schlüssel gehören nie in ein Repository.
2. Mit curl
Benötigt curl und jq.
Shell
export KABIN_API_KEY="kbn_..." # create one in the dashboard under API keys
export KABIN_API_URL="https://api.kabin.dev"
AUTH="Authorization: Bearer $KABIN_API_KEY"
# 1. Check the key
curl -sS "$KABIN_API_URL/api/v1/me" -H "$AUTH"
# 2. Create a sandbox (202, state "provisioning")
SANDBOX_ID=$(curl -sS -X POST "$KABIN_API_URL/api/v1/sandboxes" -H "$AUTH" \
-H "Content-Type: application/json" \
-d '{"type":"default","ttlSeconds":3600,"name":"quickstart"}' | jq -r '.sandbox.id')
# 3. Wait until it is ready
until [ "$(curl -sS "$KABIN_API_URL/api/v1/sandboxes/$SANDBOX_ID" -H "$AUTH" | jq -r '.sandbox.state')" = "ready" ]; do sleep 1; done
# 4. Run a command
curl -sS -X POST "$KABIN_API_URL/api/v1/sandboxes/$SANDBOX_ID/commands" -H "$AUTH" \
-H "Content-Type: application/json" \
-d '{"command":"echo hello from kabin","timeoutSeconds":30}' | jq '{exitCode, stdout}'
# 5. Write and read a file
curl -sS -X PUT "$KABIN_API_URL/api/v1/sandboxes/$SANDBOX_ID/files" -H "$AUTH" \
-H "Content-Type: application/json" -d '{"path":"notes.txt","content":"hi","encoding":"utf8"}'
curl -sS "$KABIN_API_URL/api/v1/sandboxes/$SANDBOX_ID/files?path=notes.txt" -H "$AUTH" | jq -r '.content'
# 6. Stop it (disk is kept, billing stops) and delete it
curl -sS -X POST "$KABIN_API_URL/api/v1/sandboxes/$SANDBOX_ID/stop" -H "$AUTH" > /dev/null
curl -sS -X DELETE "$KABIN_API_URL/api/v1/sandboxes/$SANDBOX_ID" -H "$AUTH" \
-H "X-Ascii-Confirm-Delete: $SANDBOX_ID"
3. Mit Python
Python 3.9 oder neuer, nur Standardbibliothek.
Python
import json, os, time, urllib.request
BASE = os.environ.get("KABIN_API_URL", "https://api.kabin.dev") + "/api/v1"
KEY = os.environ["KABIN_API_KEY"]
def call(method, path, body=None, headers=None):
req = urllib.request.Request(
BASE + path,
method=method,
data=None if body is None else json.dumps(body).encode(),
headers={"Authorization": f"Bearer {KEY}", "Content-Type": "application/json", **(headers or {})},
)
with urllib.request.urlopen(req) as resp:
return json.load(resp)
sandbox_id = call("POST", "/sandboxes", {"type": "default", "ttlSeconds": 3600, "name": "quickstart"})["sandbox"]["id"]
while call("GET", f"/sandboxes/{sandbox_id}")["sandbox"]["state"] != "ready":
time.sleep(1)
result = call("POST", f"/sandboxes/{sandbox_id}/commands", {"command": "echo hello from kabin", "timeoutSeconds": 30})
print(result["exitCode"], result["stdout"], end="")
call("PUT", f"/sandboxes/{sandbox_id}/files", {"path": "notes.txt", "content": "hi", "encoding": "utf8"})
print(call("GET", f"/sandboxes/{sandbox_id}/files?path=notes.txt")["content"])
call("POST", f"/sandboxes/{sandbox_id}/stop", {})
call("DELETE", f"/sandboxes/{sandbox_id}", headers={"X-Ascii-Confirm-Delete": sandbox_id})
4. Mit TypeScript
Node 22 oder neuer. Als quickstart.ts speichern und mit node quickstart.ts starten (ab Node 22.18 werden die Typen nativ entfernt; frühere 22.x-Versionen brauchen --experimental-strip-types, alternativ npx tsx quickstart.ts).
TypeScript
const BASE = (process.env.KABIN_API_URL ?? "https://api.kabin.dev") + "/api/v1";
const KEY = process.env.KABIN_API_KEY!;
async function call(method: string, path: string, body?: unknown, headers: Record<string, string> = {}): Promise<any> {
const res = await fetch(BASE + path, {
method,
headers: { Authorization: `Bearer ${KEY}`, "Content-Type": "application/json", ...headers },
body: body === undefined ? undefined : JSON.stringify(body),
});
const json: any = await res.json();
if (!json.ok) throw new Error(`${json.status} ${json.code}: ${json.message}`);
return json;
}
const created = await call("POST", "/sandboxes", { type: "default", ttlSeconds: 3600, name: "quickstart" });
const id: string = created.sandbox.id;
while ((await call("GET", `/sandboxes/${id}`)).sandbox.state !== "ready") {
await new Promise((r) => setTimeout(r, 1000));
}
const result = await call("POST", `/sandboxes/${id}/commands`, { command: "echo hello from kabin", timeoutSeconds: 30 });
console.log(result.exitCode, result.stdout);
await call("PUT", `/sandboxes/${id}/files`, { path: "notes.txt", content: "hi", encoding: "utf8" });
console.log((await call("GET", `/sandboxes/${id}/files?path=notes.txt`)).content);
await call("POST", `/sandboxes/${id}/stop`, {});
await call("DELETE", `/sandboxes/${id}`, undefined, { "X-Ascii-Confirm-Delete": id });
Was passiert ist
POST /api/v1/sandboxesantwortet mit202, solange die Sandboxprovisioningist; fragen SieGET /api/v1/sandboxes/{id}ab, bisstatereadyist. Ein früher gesendeter Befehl wartet bis zu 60 Sekunden darauf.- Beim Stoppen wird die Disk gespeichert und die Messung endet;
resumestartet die Sandbox wieder von dieser Disk. Arbeitsspeicher und laufende Prozesse überstehen das Stoppen nicht. - Zum Löschen ist der Bestätigungs-Header
X-Ascii-Confirm-Delete: <sandboxId>nötig (ein fester Wire-Name); das Löschen ist unumkehrbar. - Sandboxes stoppen nach
ttlSecondsohne Aktivität automatisch (Standard eine Stunde).
Weiter: API-Referenz, API-Schlüssel mit engeren Scopes und Fehler.
Diese Beispiele wurden gegen die Routentabelle und die Antwortformate des API-Servers geprüft und gegen eine lokale Testinstanz ausgeführt, nicht gegen die Produktion.