# HTTP API

> HTTP routes called by the SDKs to manage sandboxes, stream session I/O, and inspect runs.

This is the Markdown of https://docs.dvm.run/reference/http/. Every page of the dvm.run docs is served as Markdown at its address plus `.md`; the list of pages is https://docs.dvm.run/llms.txt.

All three SDKs call this HTTP API. Use this page to call it directly; it lists only the routes the SDKs use. Rust types live in [`dvm-api`](https://docs.rs/dvm-api), and every JSON field below matches them.

## Request conventions

* **Base URL:** `https://sandbox.dvm.run/api` plus the route.
* **API key:** every route except login requires `Authorization: Bearer <key>` ([Getting in](/start/access/)).
* **Bodies:** JSON (`Content-Type: application/json`), except input requests and output/file responses, which are raw bytes.
* **Errors:** an HTTP error status and a JSON body with `message` ([Errors](/reference/errors/)).
* **Numbers:** IDs, offsets, versions, and seeds are integers below 253.

## Sandboxes

### `POST /sandboxes`

Creates a sandbox and returns `201` with it. Request body fields:

| Field         | Type                                                                               | Left out          |
| ------------- | ---------------------------------------------------------------------------------- | ----------------- |
| `image`       | an image reference, as `docker run` takes it                                       | needed            |
| `command`     | argv                                                                               | none              |
| `entrypoint`  | a string                                                                           | the image’s       |
| `cpus`        | integer                                                                            | 1                 |
| `memory_mib`  | integer                                                                            | 1024              |
| `seed`        | integer                                                                            | 0                 |
| `name`        | string                                                                             | from the image    |
| `environment` | `[{"name": …, "value": …}]`                                                        | the image’s alone |
| `network`     | `{"mode": "public"}`, `{"mode": "none"}`, or `{"mode": "allowlist", "allow": […]}` | `public`          |

Omitting both `command` and `entrypoint` creates a [session](/guides/sessions/) (a sandbox that accepts commands). See [One-program sandboxes](/guides/programs/) for parameter ranges.

Every sandbox route returns a sandbox object with these fields:

| Field             |                                                                                                          |
| ----------------- | -------------------------------------------------------------------------------------------------------- |
| `id`              | its id                                                                                                   |
| `spec`            | the fields above, as the sandbox has them now                                                            |
| `run.state`       | `{"kind": …}`: `queued`, `running`, `paused`, `exited` with `code`, `stopped`, or `failed` with `reason` |
| `run.version`     | grows with every change to the run                                                                       |
| `run.inspectable` | whether its run can be inspected now                                                                     |

### `GET /sandboxes/{id}`

Returns the sandbox. With `?newer_than=<version>`, waits until the run’s version passes that value or about 30 seconds elapse (how the SDKs wait for state changes). Returns `404` if missing or not yours.

### `POST /sandboxes/{id}/pause`, `/resume`, `/stop`

Pauses, resumes, or stops the run and returns its `run`. Returns `409` if invalid in the current state (such as after ending).

### `PUT /sandboxes/{id}/network`

Updates where outbound connections may go and returns the sandbox. Body is a `network` object as above. Returns `409` once ended.

## Session input and output

Sessions run over byte streams: append frames (a JSON header line plus raw payload bytes) to input and read response frames from output ([The sandbox protocol](/reference/wire/)).

### `POST /sandboxes/{id}/input?offset=<n>&end=<true|false>`

Appends the raw body (`application/octet-stream`, max 64 KiB) at byte `offset` from the start of input. Returns `{"length": <n>, "ended": <bool>}`.

* An `offset` below the current length skips already-received bytes (safe to retry); past the length is rejected.
* `end=true` closes input after this chunk; the session server reads up to there and exits.
* Waits while the sandbox has not consumed earlier input.
* Returns `409` for a one-program sandbox (`this sandbox runs a program and takes no input`), unstarted or ended sandboxes, or already-ended input.

### `GET /sandboxes/{id}/output?offset=<n>&stderr_offset=<m>`

Returns bytes written by the first process after stdout `offset` and `stderr_offset` as one frame ([Output frames](/reference/wire/#output-frames)). With `offset`, waits up to about 30 seconds for new bytes; without, returns immediately from the start. For a session, stdout holds session server response frames; for a one-program sandbox, its own output.

## Inspection

Available once a sandbox exits ([Inspecting a finished run](/guides/inspect/)).

### `POST /sandboxes/{id}/points/seek`

Body takes `target` and optional `watch_points` (events to stop on):

* `target`: `{"kind": "end"}`, `{"kind": "at_ns", "ns": …}`, or `{"kind": "event", "thread": …, "event": …}`.
* `watch_points`: up to 32 objects, each `{"kind": …}`: `syscall`, `named_syscall` with `name`, `page_fault`, `processes`, `file_syscalls`, or `socket_syscalls`.

Returns the point reached:

| Field                        |                                                                                                                        |
| ---------------------------- | ---------------------------------------------------------------------------------------------------------------------- |
| `thread`, `process`, `event` | the thread it stopped in, its process, and the thread’s event count                                                    |
| `recording_ns`               | about when, in the recording’s time, if known                                                                          |
| `at`                         | one of `{"syscall": {number, name, args, decoded}}`, `{"page_fault": {address, write, present}}`, `{"arrival": {rip}}` |
| `operations`, `stats`        | counts up to there                                                                                                     |

### `POST /sandboxes/{id}/points/step`

Send `{"thread": …, "event": …, "watch_points": […]}` to advance from that point to the next watched event. Returns the new point, or `null` when no more watched events remain.

### `GET /sandboxes/{id}/fs/stat`, `/fs/list`, `/fs/read`

Query parameters: `thread`, `event`, and an absolute `path`; `/fs/stat` also accepts `follow_symlinks=true|false`. At that point in the run:

* `/fs/stat` returns the file’s metadata: `type`, `mode`, `uid`, `gid`, `size`, `links`, `mtime` and `ctime` as `[seconds, nanoseconds]`, a symlink’s `target` as hex bytes, and its `mount`.
* `/fs/list` returns the directory’s entries: `name`, `raw_name` as hex bytes, and `type`.
* `/fs/read` returns the raw file bytes.

If the sandbox is not currently held at the named point, it seeks there again first.

## Login

`dvm-run login` calls these endpoints without an API key:

* `POST /cli-logins` with `{"machine": "<name>"}` returns `approve_url`, `code`, `collect_token`, and `expires_at`.
* `POST /cli-logins/key` with `{"collect_token": "…"}` waits up to 30 seconds and returns `null` until approved, then returns the new key once as `secret`.

The CLI then calls `GET /me` with the new key to display who you are signed in as.
