Skip to content

Machines

Every operation here is also in the dashboard under Machines (the saved definitions) and Leased machines (see In the dashboard). Paths are relative to /v1/kiln. Field details are in the API reference. Permissions are machines::read, machines::manage and machines::exec.

Create a machine

POST /machines saves a machine definition. start and sequence are required. Add start: true and minutes to start it at once. Without start: true it is only saved, and nothing is paid.

{
  "name": "test-shop",
  "image": "ubuntu-24.04",
  "size": 1024,
  "disk": 5,
  "egress": "allowlist",
  "intake": [{ "media": "/apps/shop/src", "to": "/srv/shop" }],
  "cwd": "/srv/shop",
  "env": { "CI": "true", "NPM_TOKEN": { "global_env": "NPM_TOKEN" } },
  "start": true,
  "minutes": 60,
  "sequence": { "steps": ["npm ci", "npm test"] },
  "run_as": "prn:role:maintainer"
}
Field Meaning
start true starts the machine at once and runs the start sequence. false only saves the definition: the machine is saved until you start it. Required
minutes Length of the lease, from 5 to your tier's longest lease. Required with start: true, and refused with start: false, because minutes are given when the machine starts. It is paid at the start
project_env dev or live, the project env this lease is for. Default dev. Used with start: true, and refused with start: false, because the env is chosen when the machine starts. See the env of a lease
sequence The start sequence. Required
size, disk, image size is memory in MiB (128, 256, 512, 1024, 2048 or 4096), disk is GiB, image is ubuntu-24.04 or debian-12. See Sizes and limits. Defaults: 128 MiB, 2 GiB, ubuntu-24.04
egress, extra_hosts allowlist (default) or closed, and up to 9 extra host names. See Network
env, cwd Environment and the start directory of the sequence: any absolute path, and Kiln creates it when it is missing. There is no default code folder
intake The machine's default code: files from Media to put in before the sequence runs, kept for the starts that give no intake of their own. With start: true the first start takes it in too
run_as The machine's run identity

Send an Idempotency-Key header so a retry returns the first result instead of paying twice.

With start: false the answer is 201 with the machine, saved. With start: true it is 202. The machine is pending while Kiln takes payment and reserves room, then moves through the states below. Poll it or listen for the events.

A project keeps at most 100 machines. A saved machine does not count toward your tier's machines at once. Only leased machines do.

The start sequence

The start sequence is the machine's main process, the way a container's command is. The machine runs while it runs and ends when it exits, with its exit code. It is the sequence field: { "steps": [...] } or { "command": [...] }, never both.

  • Give steps, a list of shell lines (at most 200, each at most 8 KiB), run in order by /bin/sh -e. The first step that fails ends the sequence with that step's exit code.
  • Or give command, one program and its arguments, run without a shell.
  • Files from intake are in place before the first line runs.
  • The sequence may start more processes, such as a server and a worker. They all end when the main process ends.
  • Kiln keeps your environment variables' custom values encrypted and never shows them again; the API returns names only. See Environment variables.
  • The log marks where each step starts, with the step's text as you wrote it. Values of variables are never printed by Kiln.

Environment variables

env is a map of variable names to values. A value is one of:

  • A string, for example "CI": "true": a custom value. The machine keeps it, encrypted (see below), as the default for its starts.
  • A global env key, { "global_env": "KEY" }. Kiln reads the project's global env key KEY for you when the machine starts, with the machine's run identity, so the value is whatever that identity may read. If it may not read it, the machine does not start and says so in its reason.

Custom values are write-only. A machine keeps each custom value encrypted with Protokol's secrets keyring, bound to that machine and that variable name, and never shows it again. The API returns names only: env_names, and env, which says for each name where its value comes from: { "kind": "global_env", "global_env": "KEY" }, { "kind": "value" } (a custom value is kept) or { "kind": "start" } (no value is kept, so a start must give one; this is a machine saved before values were kept). Logs and the audit trail carry names only, never values. A name is letters, digits and underscores and does not start with a digit, at most 100 variables, each value at most 8 KiB. PROJECT_API_TOKEN, API_HOST, PROJECT_UUID and PROJECT_ENV are set for every machine and cannot be used: a create or a start that sets one is refused with 400 and field: "env".

Who may set a value. Setting, replacing or removing a custom value needs the secrets::write protokol-kiln permission on top of machines::manage. Without it the call is refused with 403 env_secrets_forbidden. Global env keys need no extra permission, and neither does keeping a value as it is or giving a value for one start only. If Kiln can't reach the secrets keyring, the call is refused with 503 env_unavailable and nothing is stored or started.

At a start. A start that gives no env runs with the machine's own: its global keys read at that start and its kept values. A start that gives a value for a name overrides the kept value for that start only, and is not kept; the names it leaves out run with the machine's own. In the dashboard's Start dialog a variable with a kept value shows as set, and typing a value there overrides it for that start.

A job keeps its env the same way: custom values encrypted, global env keys as references. Each run starts with both.

Using a global env key: an example

A machine that installs private npm packages with a token kept in the project's global env.

1. Put the key in the global env. In the dashboard open Settings → Global environment, add NPM_TOKEN and give it a value for Dev, Live or both. Each env has its own value. Global env is kept in groups. A key lives in exactly one group, so key names are unique across groups.

2. Refer to it from the machine. The reference is just the key, never the group. The variable name in the machine can be the same or different:

{ "start": true, "minutes": 10, "run_as": "prn:role:<uuid>",
  "env": { "NPM_TOKEN": { "global_env": "NPM_TOKEN" }, "CI": "true" },
  "sequence": { "steps": ["echo \"//registry.npmjs.org/:_authToken=$NPM_TOKEN\" > .npmrc", "npm ci", "npm test"] } }

With the toolkit, --global-env NAME=KEY does the same, and can be repeated:

ptkl kiln create -m 10 --run-as prn:role:<uuid> --global-env NPM_TOKEN=NPM_TOKEN --env-var CI=true \
  --step 'echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > .npmrc' --step 'npm ci' --step 'npm test'
ptkl kiln start <uuid> -m 10 --global-env API_KEY=API_KEY

In the dashboard's machine form, add an environment variable and either type its value (in a password field: it is kept encrypted and never shown again) or choose From global env and pick a key.

3. Use it in the start sequence. It is an ordinary environment variable: npm ci reads $NPM_TOKEN through .npmrc as above, or a step can call curl -H "Authorization: Bearer $API_KEY" https://api.example.com/....

What decides the value. The env of the lease (project_env, dev or live) picks which value is read, and the machine's run identity is the one reading it. The identity must be allowed to read the group the key is in: set that in the dashboard, on the role's permissions for that group. The value is read again at every start, so a changed value reaches the next start.

When it can't be read. If the identity can't read the key, or the key has no value in that env, the start fails and the time is refunded. A machine that was saved stays saved. Its reason says, for example, the machine's run identity can't read global env NPM_TOKEN in dev. Check that the key has a value for that env and that the role can read its group.

Literal values and global keys. A plain string is a custom value: the machine keeps it encrypted and every start uses it, so it needs nothing at the start. A global key is saved with the machine as a reference and is read at each start. A job takes both the same way.

A secret does not have to touch your command line. With the toolkit, --env-var NAME (no =) takes the value from your own environment, and --env-file <file> reads NAME=VALUE lines.

States

saved -> (start with minutes) -> pending -> creating -> created -> starting -> running -> stopping -> exited -> (start again) -> starting ...
any -> failed (with a plain reason)    any -> unknown    any leased state -> expired -> saved    any -> deleted
State Meaning
saved The definition only. No lease, no files, no cost. minutes, leased_at, expires_at and started_at are empty
pending The lease is paid and a place is being reserved. When Kiln has to make room first, the machine shows waiting_for_capacity: true and its lease time starts once it has a place
creating The machine's disk and network are being made
created Leased, with the intake in, and nothing has run yet
starting, running The main process is starting, then running
stopping Stop was asked for
exited The main process ended. exit_code and oom say how. The files stay until the end time
failed The machine could not be started. reason says why. Its minutes return, and the machine goes back to saved with the reason kept until the next start
unknown Kiln cannot reach the machine for now. The last state seen and its time are shown
expired The lease ended. The files are removed, and the machine goes back to saved
deleted The machine was removed, by you or, for a job run, at the end of its lease

Every change is an event: kiln.machine.<state>.

Start

POST /machines/{uuid}/start starts the machine. The body is optional: minutes, project_env, run, intake (the code for this start; left out, the machine's default code), disk, and a sequence, env or cwd for this start.

  • A saved machine has no time left, so minutes is required. Kiln reserves room, takes payment for the whole lease, puts the intake of this start in, and runs the start sequence. Your limits are checked now, at this start. If there is no room, the answer is 503 with Retry-After, and nothing is charged.
  • project_env is for a saved start. dev or live, dev if left out. A start with time left keeps the lease's env: the same value is accepted, a different one is refused with 400 and field: "project_env". Any other value is refused the same way.
  • With run: false Kiln does the lease and the intake and stops before the sequence. The machine is created. Use it to upload a .tar.gz with PUT /machines/{uuid}/archive?path= first, then start it again, with no minutes, to run the sequence.
  • disk is for a saved start only. It sets the disk in GiB of that lease, and the size limits use it. On a start with time left it is refused with 400 and field: "disk": the disk is set when the machine is placed, so resize it instead.
  • A leased machine that is created or exited runs the start sequence again on the same files, within the time left. Do not send minutes: the answer is 409 lease_active, and extend is how you add time. run: false is refused with 400 here.
  • A machine that is starting or running answers 409 wrong_state.

Code and overrides at each start

A machine keeps default code from Media (intake), and each start may bring its own instead: intake from Media, or a .tar.gz (how). A start that leaves intake out takes the default, "intake": [] brings no code, and a list is for that start only. A start that brings code, or a new sequence, env or cwd, needs the machine's run identity (see Run identity).

sequence, env and cwd given at a start apply to that lease only. The saved definition keeps its own, and changes only through PATCH. While the machine is leased, lease_sequence, lease_cwd and lease_disk show what the lease runs when it differs from the definition. A start again within the same lease keeps what that lease last ran, including the env the lease was given: a start that changes only the sequence keeps it.

A start of a saved machine runs the definition's env with its kept values, so it needs no value given again. A variable the definition keeps no value for (a machine saved before values were kept) needs one in the start, or the start is refused with 400 and field: "env" naming the variables. A value the start gives overrides the kept one for that start only. A machine with time left whose start gives env runs with that whole environment.

A start with time left does not move the end time and always fits, because the machine keeps its room. It is how you fix and rerun without copying code in again: node_modules is still there, so the second run is quicker. After the lease ends, a new start takes new minutes and starts from clean files.

A start that fails

If the code of a start cannot come in, or no place fits the machine, the start fails. The causes are a Media path that is missing, one you may not read, Media not being installed on the project (install it from the marketplace) or being unavailable, code that is too large, or an archive with bad entries.

  • The lease is refunded in full.
  • The machine goes back to saved, and its reason says why in plain words, for example intake: /apps/shop/src was not found in Media or Kiln is out of capacity right now. Try again in a few minutes.
  • The machine is never deleted. The reason stays until the next start, which clears it.

A job run's machine is still deleted when its run ends.

In the dashboard

  • A machine whose last start failed shows it, with the reason, in the Machines list and on its page.
  • Machines lists the saved definitions. Leased machines lists the machines with time left, and each one opens to its logs, terminal and files.
  • The create form only saves a definition: Save, or Save and start…, which saves and then opens the Start dialog.
  • The Start dialog asks for the minutes of a saved machine and shows what they take from your GiB-hours and credits, or says "time left" when the machine already has some. For a saved machine it asks for the env, Dev or Live, filled in with the env the dashboard is in; a start with time left keeps the lease's and hides the choice. It shows the sequence, the start directory and, for a saved machine, the disk, filled in from the definition, and sends them only when you change them, for this start only. Its Code field takes none, a .tar.gz file, or a Media path with a folder in the machine.

Stop and signal

  • POST /machines/{uuid}/stop sends SIGTERM to the main process, waits up to 30 seconds, then kills it. POST /machines/{uuid}/stop?force=true kills at once. The machine is then exited.
  • POST /machines/{uuid}/signal with { "signal": "INT" } sends a signal to the main process: TERM, INT, HUP, QUIT, KILL, USR1 or USR2, with or without the SIG prefix. Use it to end a run early.

End lease

POST /machines/{uuid}/end-lease ends the lease now, in any state while the machine holds a lease. The main process is stopped, the files and token go as at the end time, and a saved machine goes back to saved. A machine with no lease answers 409 not_leased. The unused minutes come back, credits first and then GiB-hours; a lease costs at least 5 minutes (how it is paid). With the toolkit: ptkl kiln end-lease <machine>.

Set end_on_exit: true on a create with start: true or on the start of a saved machine, and the lease ends by itself when the main process exits: right for one-shot work. ptkl kiln create and ptkl kiln start take --end-on-exit. A job run always ends its lease on exit. Stop does not end a lease; the machine stays exited and leased, and you can start it again or end the lease. In the dashboard the machine shows "Stopped · leased until 15:21 (9 min left)" with Start again and End lease, and the Lease and Start dialogs have "End the lease when the main process exits".

Extend

POST /machines/{uuid}/extend with { "minutes": 30 } buys more time and moves expires_at. It needs an active lease: on a saved machine it answers 409 not_leased, and you start the machine with minutes instead. It is paid like a lease: GiB-hours first, then credits, at once. The total never goes past your tier's longest lease from the start. Send an Idempotency-Key. The token lasts as long as the lease can, so an extension needs no new token.

Resize

PATCH /machines/{uuid} can change name, egress, extra_hosts, run_as and env at any time. env replaces the machine's environment as a whole, for the starts that follow: a string sets a custom value, { "global_env": "KEY" } a global key, and { "keep": true } keeps the value the machine holds for that name (it can't be sent back, because it is never shown). A name left out is removed, together with its kept value. Setting, replacing or removing a value needs secrets::write protokol-kiln. It can raise size and disk only while the machine is exited or saved, and only within your tier's largest size. On a saved machine nothing is charged. On an exited machine a bigger size takes the extra memory for the minutes left from your GiB-hours first, then from credits. A smaller size refunds nothing. A saved machine may also change the other fields of its definition, such as sequence, env and cwd. intake sets the machine's default code, a list of { media, to } replacing the old one, and [] clears it. It applies to the starts that follow, not to a lease already running.

Delete

DELETE /machines/{uuid} with { "name": "<the machine's name>" } (its uuid when it has no name) removes the machine and its files, whatever its state: saved, leased, failed or expired. It always deletes. It cannot be undone, and a lease that is running ends, and its unused minutes come back. The log stays readable for 7 days.

Run identity

Every machine runs as a run identity, set with run_as, and every machine shows it in its run_as field. It decides what the machine's PROJECT_API_TOKEN may do and what a global_env variable may read. Leave run_as out and the platform picks the default for you. A create that ends with no identity is refused, so no machine starts without one. You can change it later with PATCH.

run_as Identity
prn:role:<uuid> A project role
prn:role:maintainer The project's Maintainer role
prn:api-user:<uuid> An API user
prn:forge:<app-uuid> A Forge app

It is never an admin identity.

  • Who may choose which follows run identity's rules: you may choose an identity only if you hold it. The Owner and Maintainers may choose any non-admin role and any API user.
  • Asking for an identity you may not choose, or having none to default to, is refused with 403 run_identity_refused. The answer's reason, identity and missing say why, and the run identity page lists what you may choose.
  • Changing what a machine runs needs its identity. Starting it with a new sequence, env or cwd is refused with 403 run_identity_refused unless you hold the machine's run_as, because the new code would run as that identity.
  • A job stores its run_as, and every run uses it.

The env of a lease

A lease is for one project env, dev or live. Give it as project_env when a saved machine starts, or when a machine is created with start: true. It is dev if you leave it out. The machine's token acts in that env, and PROJECT_ENV in the machine says which. The machine shows it as project_env while it is leased, and null while it is saved. With the toolkit, ptkl kiln start and ptkl kiln create take --project-env dev|live; the global --env stays the env of the API call itself.

ptkl and PROJECT_API_TOKEN in every machine

Every machine, and every job run, has ptkl installed. Its environment holds:

Variable Value
PROJECT_API_TOKEN A token for the machine's run identity. It holds what that identity holds
API_HOST The platform API ptkl calls
PROJECT_UUID The project
PROJECT_ENV dev or live: the project_env of the lease, and the env the token acts in. ptkl and the SDK use it

These are the names @ptkl/sdk reads, so scripts that use the SDK work in a machine with no setup too. They are set in the start sequence, in exec and in terminal sessions. ptkl uses them with no setup, so ptkl forge bundle, or any other ptkl command the identity may run, works in the machine as it does on your computer.

  • The env is fixed for the lease. A machine started for live stays live until the lease ends, through every start, stop and extend; the next lease takes the env you give it. Its token acts in that env only.
  • The token lasts while the lease can, and stops working when the lease ends, including when you end the lease or delete the machine. Stopping the machine does not end the lease.
  • The four names are reserved. You cannot set them in env.
  • The API never returns the token, and Kiln does not keep it.
  • Anyone who can run commands in the machine or read its files can read the token. So exec, terminal and files need you to be allowed to use the machine's run identity. Logs do not.

Choose the identity for the work

Pick a run identity that holds only what the work needs. Code in the machine, such as an install script, can use everything that identity may do.

Example: build and upload a Forge app

Run as an identity that may upload Forge apps:

{
  "size": 2048,
  "run_as": "prn:role:<uuid>",
  "start": true,
  "minutes": 60,
  "sequence": { "steps": ["cd /srv/shop", "npm ci", "npm run build", "ptkl forge bundle --upload"] }
}

Uploading does not make the app live. Going live is still a person's yes.

The default allowlist already lets npm and the platform API through.