Agents
Any AI agent can lease and use Kiln machines. The kiln_* tools are part of the platform's MCP server, so an AI coding assistant, an agent you built, and a Workforce agent all use the same tools. Kiln does not know a caller is an agent: an agent is checked the same way as a person or a workflow, acts with the permissions of the user or API user it connected as, and its machines count toward your tier's limits like anyone's.
An agent needs the tools and the permissions: machines::manage to lease and control a machine, machines::exec to run commands and work with files, and machines::read for logs and status. Grant them like any other permission. An agent connected to the MCP server has the Kiln tools at once; a Workforce agent gets them in its Workforce settings.
Every machine an agent leases has ptkl and a PROJECT_API_TOKEN for its run identity, so the agent can run ptkl commands in the machine (details). To run commands or use files in a machine, the agent must be allowed to use the machine's run identity.
The tools
The tools are thin wrappers over the API, called with the token the agent connected with, so the agent can do exactly what its permissions allow.
Machines
| Tool | What it does |
|---|---|
kiln_lease |
Saves a machine and starts it at once, for a length in minutes (required), with a size (128 MiB if none), a disk in GiB, a project_env (dev or live, default dev: the token and PROJECT_ENV follow it), the start sequence and the code of this start: intake from Media (also kept as the machine's default code; [] keeps none), and the agent's own files (files, up to 8 MiB in all, unpacked in files_to, which is required with files). Returns the machine's uuid, expires_at and what it cost |
kiln_list |
Lists the project's machines with state and time left, so the agent can find one again. A saved machine has no time left |
kiln_status |
State, exit code, memory, swap, CPU, disk and out-of-memory kills |
kiln_exec |
Runs one more command in the running machine. detach: true for a long one, whose output goes to the log |
kiln_logs |
Reads the main process's log |
kiln_wait |
Waits up to 50 seconds per call for the exit or for a text such as "ready", and returns the state and exit code; on timed_out call it again |
kiln_start |
Starts a machine. While time is left it runs the start sequence again, or a new one, on the files left after the exit. A saved machine has no time left, so it takes minutes and pays them, and may take a disk and a project_env (dev or live) for that lease. Each start brings its own code: intake (left out, a saved machine takes its default code; [] brings none), or files with files_to. A sequence, env or cwd given applies to that run only; an env value given overrides the machine's kept value of that name for that start |
kiln_end_lease |
Ends the lease now. Unused minutes come back, credits first and then GiB-hours (a lease costs at least 5 minutes), and a saved machine goes back to saved. Agents call it when their work is done. kiln_lease and kiln_start take end_on_exit to end the lease when the main process exits |
kiln_stop |
Stops the main process. The machine and its files stay until the lease ends, then it goes back to saved |
kiln_read_file, kiln_write_file, kiln_edit_file, kiln_list_files |
Work with files in the machine |
kiln_intake, kiln_export |
Take a Media file or directory into the machine, and put a path from the machine into Media. kiln_export takes media as a folder to put it in (existing, or ending in /, for example /builds/) or the full Media path to save it as (/builds/shop.tgz) |
kiln_extend, kiln_delete |
Buy more minutes for a leased machine, or delete the machine. Deleting removes the definition and returns the unused minutes |
Jobs
| Tool | What it does |
|---|---|
kiln_job_create |
Saves a job: the machine spec, a cron schedule and time_zone, and overlap (skip, parallel or queue, required). Its env maps a variable name to a key of the project's global env (prefer it for secrets); env_values maps a name to a custom value, which the job keeps encrypted and never shows again (needs secrets::write protokol-kiln) |
kiln_job_list, kiln_job_get |
List the jobs with their last run, or read one by id or name |
kiln_job_update |
Changes a job, pauses it with enabled: false, or makes it run on request only with an empty schedule. A job's env is replaced as a whole when any of env, env_values or keep_env_values (names of custom values to keep as they are) is given |
kiln_job_delete |
Deletes a job |
kiln_job_run |
Starts a run now. Answers that the job is busy when overlap does not allow another run |
kiln_job_runs, kiln_job_run_get |
List a job's runs, or read one run: state, exit code and machine. While a run goes, its machine is a normal machine, so kiln_logs and kiln_wait read it |
How it behaves
- Every reply says how much time is left (
expires_atandtime_left, the same as the API'sX-Kiln-Expires-AtandX-Kiln-Time-Left-Sec). A process still running at expiry is killed and the agent gets a "lease expired" error. The machine issavedagain, and the agent starts it with new minutes. - Agents reuse machines before making new ones. An agent keeps using the machine it already leased in the task while it has time left. Otherwise it looks at
kiln_listand starts a saved machine that fits withkiln_start. A saved machine fits when it has the requested image (the default image if none), at least the requested memory and disk, and the requested run identity.kiln_leasechecks this itself: if a saved machine fits, it creates nothing and names up to three of them. The agent passesnew_machine: trueonly when none fits the work. If the machines cannot be listed, the lease goes on. - End the lease when the work is done. Unused minutes come back, so an agent calls
kiln_end_lease, or setsend_on_exitfor one-shot work. - A lease is disposable. The files go when it ends. The definition stays. Work that must last goes to Media with
kiln_exportbefore the end. - Out of memory is reported. The result says the machine ran out of its size and lists the bigger ones, so the agent can lease a bigger machine and try again.
- Limits and payment are your tier's: machines at once, largest size, longest lease. Each lease is paid when it starts.
- Replies stay plain. They show names, states and times, not identity ids or placement details.
- Egress defaults to the allowlist: package registries and the platform API.
Example: build and upload a frontend app
kiln_lease: a 2 GiB machine, started for one hour, running as an identity that may upload Forge apps (run_as). The code isintakefrom Media, or files the agent wrote. The start sequence isnpm ci,npm run build,ptkl forge bundle --upload.kiln_logs: the agent waits for the main process to exit and reads the build output.- Exit 0: the upload, made by
ptklwith the machine'sPROJECT_API_TOKEN, is recorded. Not 0: the agent reads the log, fixes the code withkiln_edit_fileand callskiln_start.node_modulesis still in place, so the second run is quicker. - Deploying the uploaded version uses the existing
forge_*tools, which still need a person's yes to go live. kiln_end_lease(orend_on_exitfrom the start),kiln_delete, or the lease ends. Billing stops and unused minutes come back, and the machine goes back tosavedwhen the lease ends, or is gone when deleted. The results are the Forge version, and the log stays readable for 7 days.