The micro-VM for AI agents — light enough to embed on your laptop, elastic enough to power an agentic cloud.
SDK API for run-command semantics
Date: 2026-07-14
Status: Design — pending review
Depends on: run-command-semantics-fix.md (core implemented: options.cmd
= init, attach()/attach_exec(), init exit codes, box-stops-on-exit)
Problem
PR 1 gave the core docker semantics, and almost none of it is reachable from
the SDKs. The one exception it ships: Python's attach(execution_id=None)
already takes the no-arg form (docker-py's shape), so a Python caller can
reach the main command — but has no way to make one, because BoxOptions
exposes neither cmd nor tty, and Node's JsBoxOptions exposes neither
either. Today's Python surface (Node mirrors it via napi):
- Raw layer:
Boxlite.create(BoxOptions) -> Box{exec, attach(execution_id=None), copy_in/out, stop, …}—BoxOptionsdoes not exposecmd/entrypoint/tty; there is no wait and no exit code anywhere. - Facade layer:
SimpleBox(+ codebox/browserbox/…) — pure boot-and-exec.
So an SDK user cannot express the exact scenario that motivated PR 1
(run this image with THIS command as its main process; observe its exit).
Personas (this is the design driver)
| A: sandbox (today's users) | B: docker-style (unlocked by PR 1) | |
|---|---|---|
| Flow | boot once, exec many | run one command to completion / as the workload |
| Peers | E2B, Daytona (no run-command at all) | docker-py containers.run, testcontainers |
| Exit codes | data (agent frameworks branch on them) | the result |
| Compat | must stay byte-identical (agent-base daemon boxes) | new surface |
Design (Python shown; Node mirrors naming in camelCase)
1. Options: thin parity (raw layer)
BoxOptions gains cmd: list[str] | None and entrypoint: list[str] | None
(plus user/working_dir passthrough if not already mapped). Semantics
documented once, as the docker matrix: cmd replaces the image CMD; the image
ENTRYPOINT is preserved; the result is the container's init and the box stops
when it exits.
2. Box: two additions (raw layer)
box.attach() -> Execution # main-command session (no-arg default)
box.attach(execution_id) # exec-session reattach — UNCHANGED callers
await box.wait() -> BoxResult # blocks until the box stops
- One SDK method, optional selector (docker-py/dockerode shape; and
containerd's wire uses the same idea — empty
exec_idtargets init). Existing positionalattach(id)callers keep working; the no-arg call is the main-process attach. No deprecation cycle needed. - Rust core: two methods (moby Go-client shape) — done in PR 1 (the
old names were never released):
attach_init()→attach()(main), WS-reconnectattach(execution_id)→attach_exec(execution_id). The wire underneath is kata's: the host setsContainerInitRequest.execution_id = container_id, soattach()addresses init with the id the host itself declared.attach(Option<&str>)was considered and rejected:attach(None)is an opaque mode-selector at Rust call sites, and split methods give honest per-backend defaults (local:attach✓ /attach_execunsupported; REST: the reverse, until the cloud grows main-attach). - "init" is runtime-internal vocabulary — it appears in no peer's public
API; the naming rule everywhere is unqualified
attachon the box receiver, qualification on the exec variant, selector optionality in the layer's native idiom. - Wire layer unchanged: reserved id (
execution_id = container_id, kata-style) — ourAttachRequest.execution_idis required-non-empty and the duplicate-id guard already protects the convention. wait()follows docker-py'sContainer.wait()(which returns{'StatusCode': N}) but returns a typedBoxResult(exit_code: int)— no dict-of-unknowns. Implementation: Wait RPC when live, status/exit-code polling via inspect when reattaching after the VM self-stopped.
3. Boxlite.run(): the docker-py-shaped convenience (facade layer)
result = await rt.run("alpine", ["sh", "-c", "make test"])
# RunResult(exit_code=2, stdout=b"...", stderr=b"...")
box = await rt.run("oven/bun:1.2.1",
["bun", "-e", "Bun.serve(...)"],
detach=True, options=BoxOptions(ports=[(9101, 80)]))
# Box — the server IS init; the published port serves; box.wait() later
detach=False(default): create → start → attach_init → stream to completion → auto-remove (docker-pyremove=Truebehavior is our default here;keep=Trueopts out) → returnRunResult{exit_code, stdout, stderr}.detach=True: return theBoximmediately.- Deliberate deviation from docker-py: non-zero exit does not raise
(docker-py raises
ContainerError). Persona A is the primary market — agent frameworks treat exit codes as data (every integration we ship branches onresult.exit_code); exceptions-for-exit-codes forces try/except around ordinary control flow. docker-py parity is oneif result.exit_code != 0: raiseaway for those who want it. - stdout/stderr collected with a size cap (default 8 MiB, configurable;
streams available via
detach=True+attach_init()for unbounded output).
4. Explicit non-changes
SimpleBoxand every specialty box: byte-identical behavior (create withoutcmd→ image default init → boot-and-exec unchanged).- Existing
exec/attach(execution_id): unchanged. - Go and C SDKs: deferred until the Python/Node shape survives review — their thin cores make mirroring mechanical once names are settled.
Verification
- Python + Node integration tests mirroring the CLI S-tests: run-to-completion
exit code; detached server reachable then
wait()returns its code;attach_initstreaming; SimpleBox suite untouched and green. - Doc examples are executable (the bun scenario above is the acceptance test).
Open questions
RunResultno-raise vs docker-py'sContainerError— recommended no-raise (persona A), confirm.rt.run(image, cmd)naming vsrt.create(...)+box.attach_init()only (no convenience) — recommended: ship the convenience; it is the README's four-act story ("Run") in one call.- Default auto-remove on
detach=Falseruns — recommended yes (docker-pyremove+ our--rmprecedent),keep=Trueto opt out.