Commands, files and logs
Everything goes through the Kiln API, so it carries your identity, permissions and audit. Nothing connects to the machine directly. Running commands and working with files needs machines::exec, and you must be allowed to use the machine's run identity, because these calls can read its PROJECT_API_TOKEN. Logs, wait and status need machines::read. Paths are relative to /v1/kiln.
Every reply tells you how long the lease has left: expires_at and time_left_sec in a JSON answer, and the headers X-Kiln-Expires-At and X-Kiln-Time-Left-Sec on answers that are bytes (a file, an archive) and on the followed log.
All of this needs an active lease. A saved machine has no files and no process, so these calls answer 409 not_leased. Start it first, with minutes. Logs of past leases stay readable.
| What you can do | Needs the machine to be |
|---|---|
| Run a command, stream, terminal | running |
| Read and write files, archives, intake, export | created, running or exited |
| Logs, status | Any state |
| Wait | Any state. On an exited machine it answers at once |
Run a command
POST /machines/{uuid}/exec runs one more command in a running machine and answers with its result.
{
"command": ["python3", "-"],
"stdin": "print('hello')",
"env": { "TOKEN": "..." },
"cwd": "/srv/app",
"timeout_sec": 60
}
{ "exit_code": 0, "stdout": "hello\n", "stderr": "", "truncated": false, "timed_out": false, "expires_at": "2026-11-20T11:00:00Z", "time_left_sec": 3412 }
timeout_secis at most 900 and defaults to 900. Each stream is at most 1 MiB, thentruncatedistrue(andstdout_truncatedorstderr_truncatedsays which).timed_outistrueif the timeout ended it.userruns the command as another user in the machine.stdin_base64sends bytes instead of text.- The answer also says how long the lease has left:
expires_atandtime_left_sec. detach: truereturns at once, and the command's output goes to the machine's log instead. Use it for a long-running second process. A detached command ends with the main process, and if it runs the machine out of memory, the whole machine ends.- Where it runs. The command starts in the lease's start directory and has the machine's environment, as the start sequence does, including
PROJECT_API_TOKEN,API_HOST,PROJECT_UUIDandPROJECT_ENV. Givecwdorenvto override: the call wins per name, and the machine's other variables stay. Pass secrets, such as a private repository's token, inenv. Kiln does not keep them.
Stream a command
GET /machines/{uuid}/exec/stream is a websocket: stdin goes in, stdout, stderr and the exit code come out. Timeout up to 24 hours. Send a start frame first with the command (and optionally env, cwd, user, timeout_sec).
Terminal
GET /machines/{uuid}/terminal?rows=&cols= is a websocket with a terminal and resize messages. It opens in the lease's start directory with the machine's environment, like a command. The dashboard's Terminal tab uses it. It closes after 30 minutes without activity.
From the toolkit: ptkl kiln terminal <uuid> opens that shell in your own terminal, like ssh. It sends your window size and every resize, passes Ctrl-C and the other keys to the machine's shell, and exits with the shell's exit code. Piped input works too (echo ls | ptkl kiln terminal <uuid>; the end of the input closes the shell's stdin). The server pings every 20 seconds; when the pings stop for about 45 seconds the session ends with "connection to the machine lost" and your terminal is put back as it was. It needs the machine running and machines::exec; if either is missing it prints the server's message and exits 1. The shell is the machine's default (bash -l, else sh); to run one command use ptkl kiln exec.
Websocket frames
If you write your own client for the stream or the terminal, this is what goes over the socket. Bytes travel in binary frames, and the first byte says what they are, so no byte is changed and nothing is base64. Everything else is a JSON text frame with a type.
| From | Frame | Meaning |
|---|---|---|
| you | binary 0x00 + bytes |
stdin |
| you | { "type": "start", "command": ["npm", "test"] } |
First frame of an exec stream. Also env, cwd, user, timeout_sec |
| you | { "type": "resize", "rows": 40, "cols": 120 } |
Resize a terminal |
| you | { "type": "close_stdin" } |
End of input |
| Kiln | { "type": "ready", "exec_id", "expires_at", "time_left_sec" } |
The stream is open |
| Kiln | binary 0x01 + bytes |
stdout. A terminal's only output |
| Kiln | binary 0x02 + bytes |
stderr |
| Kiln | { "type": "exit", "exit_code", "timed_out" } |
The command ended |
| Kiln | { "type": "error", "code", "message", "status" } |
The stream ended, then the socket closes. code is lease_expired, idle_timeout, session_limit, refused or failed |
The API reference has the full list of fields.
Files
| Route | Purpose |
|---|---|
GET /machines/{uuid}/files?path=&offset=&length= |
Read a file, whole or a byte range. The answer is the bytes |
PUT /machines/{uuid}/files?path=&mode= |
Write one file. The body is the bytes and Content-Length is required. mode is octal and defaults to 0644 |
POST /machines/{uuid}/files/edit |
Replace an exact piece of text. Refused if it is not found exactly once, or if the file changed since it was read |
POST /machines/{uuid}/files/list |
A directory tree to a depth, with sizes and times. Body: { "path": "/srv/app", "depth": 2 } |
A file read answers its size, mode and time in the headers X-Kiln-File-Size, X-Kiln-File-Mode and X-Kiln-File-Modified. To write several files at once, send an archive. A file is at most 100 MiB. Files are binary-safe, and count against the machine's disk. Moving, deleting and searching files is best done with a shell command through exec.
Archives
PUT /machines/{uuid}/archive?path=unpacks a.tar.gzbody at a path in the machine. Up to 100 MiB.GET /machines/{uuid}/archive?path=downloads a path as a.tar.gz. Up to 100 MiB.
From the toolkit: ptkl kiln push ./dir sends a directory.
Code comes with each start
A machine may keep default code from Media, which each start takes in unless it says otherwise. Each start can also bring its own code, which lets one machine run different tasks. Code is optional: a sequence may fetch its own.
The start directory. Code goes to the folder you give, which can be any absolute path. Without one it goes to that start's directory: the cwd of the start, or else the machine's cwd. Kiln creates the directory when it is missing. There is no default code folder, and with no folder at all the toolkit asks for one. Paths such as /srv/app in these pages are only examples.
From Media. The project needs Media installed from the marketplace; without it the start is refused with 409 media_not_installed before anything is charged. Give intake on the start, or keep it as the machine's default code. Kiln copies each Media path in after the machine is placed and before the sequence runs, with the credentials of whoever starts it:
The contents of a Media folder land directly in to, and a single file lands as to/<file name>. Media paths are absolute. If the code cannot come in, the start fails and the machine stays saved: see A start that fails. A start that brings an intake needs the machine's run identity. A start with time left may bring an intake too.
Default code. A machine keeps an intake of its own, a list of { media, to } (at most 20, absolute paths), set when you create it (with start: false, or with start: true, where the first start uses it too) or with PATCH /machines/{uuid}. It is returned by GET and in the list, always as a list ([] when there is none). When a saved machine starts, the intake of the start decides what comes in:
The start's intake |
What comes in |
|---|---|
| Left out | The machine's default code |
[] |
No code |
| A list | That list, for this start only. The default stays as it was |
A start that brings the default goes through the same checks as one that gives the list: the machine's run identity, Media installed on the project (409 media_not_installed before anything is charged), the intake itself, and the refund when it fails. A start with time left runs again on the files it has, so it does not take the default in again; give an intake to bring files in. Saving or changing a default checks the paths and the limit only; Media is checked when a start brings the code. A .tar.gz is never a default: it is uploaded at each start. A job has its own intake and never uses a machine's default.
From a .tar.gz. The archive goes in between two starts:
POST /machines/{uuid}/startwith{ "minutes": 30, "run": false }.- Wait for the state
created. PUT /machines/{uuid}/archive?path=/srv/shopwith the.tar.gzas the body.POST /machines/{uuid}/startwith{}.
With the toolkit. ptkl kiln start <uuid> --media <path>, --archive <file.tar.gz|dir> and --to <folder> do these steps for you. A directory given to --archive is packed, with .gitignore respected. Without --to, the code goes to the start's directory (--cwd, else the machine's own). With neither, the command stops with --to is needed: the machine has no start directory. ptkl kiln create --media/--archive works the same way for a machine that starts at once; --media also becomes the machine's default code, with --no-start as well. ptkl kiln start <uuid> --media <path> brings code for that start only, --no-code brings none, and without either the machine's default comes in. ptkl kiln machines update <uuid> --media <path> (repeatable) replaces the default and --no-media clears it; ptkl kiln machines get <uuid> shows it as intake. ptkl kiln push <dir> <uuid> --to <folder> packs a directory into a leased machine.
In the dashboard. The Start dialog has a Code field: none, a .tar.gz file, or a Media path with a folder in the machine. The Files tab of a leased machine has Take from Media and Export to Media.
Into a leased machine. The project needs Media installed from the marketplace; without it this answers 409 media_not_installed. Any number of times while it has a lease: POST /machines/{uuid}/intake with { "media": "/apps/shop/src", "to": "/srv/shop" }.
- Folder or file. The contents of a Media folder land directly in
to, as if you copied the folder's contents. A single file lands asto/<file name>. The Media path must be absolute, such as/apps/shop/src. - Kiln creates
towhen it is missing. - Kiln reads Media with your own credentials, so Media's permissions decide what you can take. Kiln keeps no copy.
- The size limit is the machine's disk.
- It works with egress
closed.
Export to Media
Exporting needs Media installed on the project from the marketplace; without it the export answers 409 media_not_installed.
Getting anything out is your choice, and nothing is exported by itself. Until the end time you can:
- Download a path as a
.tar.gz, or POST /machines/{uuid}/exportwith{ "path": "/srv/app/dist", "media": "/builds/shop" }. A file is uploaded as one file, and a directory as one.tar.gz.mediaworks like the destination ofcp: an existing Media folder, or a path ending in/, takes the file inside it under its own name ("media": "/builds/"gives/builds/dist.tar.gz); any other path is the full Media path to save it as ("media": "/builds/shop.tgz"gives exactly/builds/shop.tgz, in a folder created if needed, and may replace a file there). The answer'snameis the name it got in Media. It uses your own credentials, so the file sits in Media with Media's permissions, sharing and retention after the machine is gone. The limit is 500 MiB. The answer is{ "kind", "name", "bytes" }.
A job can also push its own output, for example a Forge upload with ptkl and the machine's PROJECT_API_TOKEN, or a call to the platform API, which is always on the allowlist.
Logs and wait
The log is the main process's stdout and stderr, with timestamps and the stream marked. It also holds the output of detached commands, tagged with the command's id, and the marker for each start step.
GET /machines/{uuid}/logs?since=&follow= reads it. since is an RFC 3339 time. Without follow the answer is { "lines": [ { "time", "stream", "exec_id", "text" } ] }. Kiln keeps the last 10 MiB of each machine's log, and keeps it for 7 days after the lease ended or the machine was deleted.
Follow the log
GET /machines/{uuid}/logs?follow=true answers a chunked stream of newline-delimited JSON (application/x-ndjson), one object per line, and keeps the connection open:
{"event":"ready","expires_at":"2026-11-20T11:00:00Z","time_left_sec":3412}
{"event":"line","line":{"time":"2026-11-20T10:03:01Z","stream":"stdout","text":"installing"}}
{"event":"end","reason":"exited"}
ready comes first, then one line per log line, then one end with the reason: exited when the main process ended, lease expired, or a short reason for a failure. The HTTP status is already 200 once the stream has begun, so a failure after that is the end event's reason.
Wait
GET /machines/{uuid}/wait?timeout_sec=&until=exit|text&text= waits up to 300 seconds (60 if you do not say) for the main process to exit (until=exit), or for a text to appear in the log (until=text, for example text=ready). It answers with the state, the exit code and the log line that matched. It saves you from polling.
Status
GET /machines/{uuid}/status reports memory, swap and CPU use, disk used, out-of-memory kills and uptime. Use it to choose the next size.
See what's running
- Status shows memory, swap, CPU, disk and uptime for the machine as a whole.
- Processes (
GET /machines/{uuid}/processes) lists each process with its CPU, memory, user and command line, busiest first, liketop. It needs the same permission as running a command. - In the Terminal tab, run
toporhtopfor a live view.