# Machines

Every task on this page is one API call. Where the CLI has a command for the task, the command comes first, and [CLI](cli.md) has its flags. The examples use a machine named `calm-river-otter`, and the `curl` examples read the API key from `ARVM_API_KEY`.

## Create a machine

```console
$ arvm new --size default
```

The command returns when the machine is running, and prints the machine with its name and its SSH command. [Quickstart](quickstart.md#4-create-a-machine) shows what it prints.

The same request through the API. `?wait=running` holds the response until the machine is up, for at most 60 seconds.

```console
$ curl -s -X POST "https://api.arvm.dev/v1/machines?wait=running" \
    -H "Authorization: Bearer $ARVM_API_KEY" \
    -H "Idempotency-Key: $(uuidgen)" \
    -H "Content-Type: application/json" \
    -d '{"size": "default"}'
```

Every field of the request is optional. `{}` creates a machine of the default size, image and region with a generated name.

| Field | What it sets |
|---|---|
| `name` | The machine's name. Lowercase letters, digits and hyphens, at most 48 characters, starting with a letter. Three generated words when you leave it out. |
| `size` | `small`, `default` or `large`. |
| `labels` | Up to 32 key and value pairs, to find and group machines. |
| `env` | Up to 128 environment variables, set for every session and command in the machine. |
| `idle_timeout_seconds` | The [idle stop](#idle-stop) limit. `null` turns idle stop off. |
| `ssh_key_ids` | The SSH keys to install in the machine. Every key of the org when you leave it out. |
| `inbound` | `open` or `closed`: whether the internet can connect to the machine's [IPv6 address](connect.md#ipv6). `open` when you leave it out. |
| `from_snapshot` | A [snapshot](snapshots.md) to copy the disk from, in place of the image. |
| `setup_script` | A script the machine runs once, when it first runs. See [Run a setup script](#run-a-setup-script). |

If the response does not arrive, send the request again with the same `Idempotency-Key`. For 24 hours after a create succeeds, the same key and body return the first response and create nothing new.

Create fails with one of these codes:

| Code | Status | Meaning |
|---|---|---|
| `insufficient_balance` | 402 | The balance is zero. Subscribe or top up. |
| `limit_exceeded` | 403 | A [limit](#limits) of the plan is reached. |
| `name_taken` | 409 | Another machine of yours has the name. |
| `no_capacity` | 503 | No server has room for the size right now. Nothing was created. Wait for the `Retry-After` seconds and send the request again, with the same `Idempotency-Key` if you sent one. |

`arvm new` prints the refusal with the seconds to wait and exits with status 9. Run the same command again.

## Run a setup script

Give a machine a script with the create, and the machine runs it once, when it first runs: install your tools, clone a repository, start a service.

```console
$ arvm new --name agent-7 --setup ./setup.sh --timeout 30m
```

`arvm new` waits until the machine is running, and then until the script has ended. With the API, the script is the `setup_script` field of the create, and `wait_setup=true` holds a response until the script has ended:

```console
$ curl -s -X POST "https://api.arvm.dev/v1/machines?wait=running&wait_setup=true&timeout=300" \
    -H "Authorization: Bearer $ARVM_API_KEY" \
    -H "Idempotency-Key: $(uuidgen)" \
    -H "Content-Type: application/json" \
    -d "$(jq -n --rawfile script setup.sh '{name: "agent-7", setup_script: $script}')"
```

A response is held for at most 300 seconds. If the script runs longer, ask again with `GET /v1/machines/agent-7?wait_setup=true&timeout=300` until `setup.state` is no longer `running`.

In the dashboard, open **Setup script** in the form that creates a machine and paste the script. The machine's page then shows where the script is, and how it ended.

What the machine does with the script:

- It runs it as `dev`, in `/home/dev`, with the machine's `env`. `dev` has `sudo` without a password.
- It runs the file itself, so the first line chooses the interpreter: `#!/bin/bash`, `#!/usr/bin/env python3`. With no such line, `bash` runs it.
- It starts it once the machine takes connections. The machine is `running` before the script has ended, so you can connect and watch.
- It runs it once. A stop and a start, a restart or a resize does not run it again, and neither does a machine created from a snapshot of this one, unless that create has a script of its own.
- It gives it 30 minutes. Then the script is killed with everything it started.
- When the script exits, what it left running in the background is stopped, as after `arvm exec`. To leave something running, start it as a service: `sudo systemctl enable --now ...`, or `docker run -d`.

The script may be 65,536 bytes of text. It can hold a token: no response, event or log shows it again, and the machine deletes its copy when the script has ended. The platform keeps the script until the machine has taken it.

The machine's `setup` says where the script is:

| `setup.state` | Meaning |
|---|---|
| `pending` | The machine has not run far enough to take the script. If you stop the machine now, the script runs when you next start it. |
| `running` | The script runs. The machine is not [idle-stopped](#idle-stop) while it does. |
| `succeeded` | The script exited with status 0. |
| `failed` | The script exited with another status, which is in `setup.exit_code`. |
| `timed_out` | The script ran for 30 minutes and was killed. |
| `interrupted` | The machine stopped or restarted while the script ran. It is not run again. |
| `unsupported` | The machine booted an image that was built before setup scripts existed, as a machine created from an old snapshot does. No script ran. |

A script that does not succeed does not fail the machine: the machine stays `running`, and you can look. `arvm new` then exits with status 11 and names the machine. The script's output, standard output and standard error together, is in the machine, where `dev` can read it. The first 1 MiB is kept.

```console
$ arvm exec agent-7 -- cat /var/log/acre-setup.log
```

The machine's [events](#see-what-happened-to-a-machine) have `setup.started` and `setup.finished`, the second with the `outcome` and the `exit_code`.

## List machines

Newest first. A machine is left out once its deletion is asked for.

```console
$ arvm ls
```

```console
$ curl -s "https://api.arvm.dev/v1/machines" \
    -H "Authorization: Bearer $ARVM_API_KEY"
```

Keep only the machines that have a label:

```console
$ curl -s "https://api.arvm.dev/v1/machines?label=env=staging" \
    -H "Authorization: Bearer $ARVM_API_KEY"
```

## Stop a machine

```console
$ arvm stop calm-river-otter
```

```console
$ curl -s -X POST "https://api.arvm.dev/v1/machines/calm-river-otter/stop?wait=stopped" \
    -H "Authorization: Bearer $ARVM_API_KEY"
```

Stop shuts the operating system down and keeps the disk. Billing for the machine ends at the request. Stopping a stopped machine succeeds and changes nothing.

## Start a machine

```console
$ arvm start calm-river-otter
```

```console
$ curl -s -X POST "https://api.arvm.dev/v1/machines/calm-river-otter/start?wait=running" \
    -H "Authorization: Bearer $ARVM_API_KEY"
```

The machine boots from its disk. Its name and its SSH address are the same as before the stop. Start fails with `insufficient_balance` when the balance is zero.

Start fails with `no_capacity` and status 503 when the server that holds the machine's disk is running all the machines it can. The answer comes at once, whatever `wait` asks for. The machine is still stopped, and you pay nothing for it. Wait for the `Retry-After` seconds and start it again: room appears when another machine on that server stops. See [When no server has room](regions-and-uptime.md#when-no-server-has-room).

`arvm start` prints the refusal with the seconds to wait and exits with status 9. So do `arvm restart` of a stopped machine, and `arvm ssh` and `arvm cp`, which start a stopped machine before they connect.

## Restart a machine

```console
$ arvm restart calm-river-otter
```

```console
$ curl -s -X POST "https://api.arvm.dev/v1/machines/calm-river-otter/restart?wait=running" \
    -H "Authorization: Bearer $ARVM_API_KEY"
```

Restart stops the machine and starts it again. Restarting a stopped machine starts it.

## Resize a machine

Stop the machine first, and wait until its phase is `stopped`: pass `?wait=stopped` to the stop. Then change its size:

```console
$ arvm stop calm-river-otter
$ arvm resize calm-river-otter large
```

```console
$ curl -s -X PATCH "https://api.arvm.dev/v1/machines/calm-river-otter" \
    -H "Authorization: Bearer $ARVM_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{"size": "large"}'
```

A machine whose phase is not yet `stopped` refuses the change with `machine_not_stopped`. The new rate applies from the next start.

When the new size has a larger disk, the host grows the disk and its filesystem on the next start. A resize to a size with a smaller disk is refused with `disk_cannot_shrink` (409); moving to a size with the same disk and fewer vCPUs or less memory is allowed. If the server or drive that holds the machine's disk has no room for the new size, or its drive cannot be reached right now, the resize is refused with `no_capacity` or `disk_unreachable` (503, with `Retry-After`) and the machine keeps its current size.

## Rename or relabel a machine

The CLI renames a machine. Labels are set through the API.

```console
$ arvm rename calm-river-otter api-staging
```

```console
$ curl -s -X PATCH "https://api.arvm.dev/v1/machines/calm-river-otter" \
    -H "Authorization: Bearer $ARVM_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{"name": "api-staging", "labels": {"env": "staging"}}'
```

`labels` replaces the whole set. A field you leave out is not changed. The machine's ID and its endpoint URLs do not change with the name.

## Delete a machine

Deleting a machine deletes its disk. This cannot be undone. Snapshots of the machine are kept.

```console
$ arvm rm calm-river-otter --yes
```

Without `--yes`, the command asks you to type the machine's name before it deletes anything. A script has nobody to answer, so without `--yes` it deletes nothing and exits with code 2.

```console
$ curl -s -X DELETE "https://api.arvm.dev/v1/machines/calm-river-otter?wait=deleted" \
    -H "Authorization: Bearer $ARVM_API_KEY"
```

The name is free for a new machine at once. By its ID, a deleted machine still answers `GET`, so a program can watch it reach the phase `deleted`.

## Phases

| Phase | Meaning |
|---|---|
| `scheduled` | Created, on the server that was chosen for it. A machine has its server from the moment it exists. |
| `creating` | The server is preparing the disk and the network. |
| `starting` | The machine is booting. |
| `running` | The machine is up and answers. Hours are counted in this phase only. |
| `stopping` | The operating system is shutting down. |
| `stopped` | The machine is off. Its disk is kept. |
| `deleting` | The server is removing the machine and its disk. |
| `deleted` | The machine and its disk are gone. |
| `failed` | A step did not succeed. The machine's `failure` field says which and why. |

Read the phase, or wait for one:

```console
$ curl -s "https://api.arvm.dev/v1/machines/calm-river-otter?wait=running&timeout=120" \
    -H "Authorization: Bearer $ARVM_API_KEY"
```

`timeout` is at most 300 seconds. When the time runs out, the response is still a success and shows the phase the machine is in. Check `phase` in the response. A wait ends early when the machine is deleted. A wait for `running` ends when the machine is not wanted running: you or the platform stopped it, and its `stop` field says why. A failure ends it that way, since the platform stops a machine that fails. A wait for `stopped` also ends when the machine's disk is lost and nothing of it runs: it stays `failed` with `disk_lost`. Any other failure ends no wait for `stopped`, since the server goes on with the stop until it is done.

The phase is the server's last report, which can be older than your last request. A machine that is wanted `running` and whose phase is `failed` is starting again after a failure: its `failure` is of the attempt before, and the phase changes when the server reports on the start.

## When the platform stops a machine

The platform stops a machine that you did not ask to stop in these cases: the balance reached zero and the grace period passed, the org was suspended, the org's subscription ended, the hardware that holds the machine's disk failed, the machine had no activity for its [idle timeout](#idle-stop), or the machine failed while it was wanted running ([When a machine fails](#when-a-machine-fails)). The stop keeps the disk. After a subscription ends, [billing](billing.md#pay-cancel-and-refunds) says what happens to it.

Such a machine has a `stop` field that says why (`reason`) and when the platform asked (`at`). The field is there from the moment the platform asks, while the machine is still `stopping`, and after it is `stopped`. A start, a restart or a delete removes it. A machine that you stopped has no `stop` field.

```json
"desired": "stopped",
"phase": "stopped",
"stop": {"reason": "subscription_ended", "at": "2026-11-13T21:00:04Z"}
```

[The schema `MachineStopReason`](api/schemas.md#machinestopreason) lists every reason. `arvm get` prints the reason and the time, and `arvm ls` prints the reason beside the phase: `stopped (subscription_ended)`.

## Idle stop

A machine is stopped when it has had no activity and its CPU utilization has stayed below the platform's idle threshold for its `idle_timeout_seconds`. The default is 3,600 seconds, which is 60 minutes. These count as activity:

- an SSH session through the gateway
- a terminal session in the dashboard
- a command run through the API
- a request to one of the machine's endpoints
- sustained CPU work above the platform's idle threshold

`last_activity_at` on the machine shows the last gateway or API activity the platform saw.

A machine is also not stopped while its [setup script](#run-a-setup-script) runs.

Direct connections to the machine's public IPv6 address do not pass through the gateway and do not update `last_activity_at`. A background job that sleeps, waits on I/O, or uses very little CPU can still be stopped once the timeout passes, so turn idle stop off before you start a long unattended job. [Run a job that outlives the request](exec-and-files.md#run-a-job-that-outlives-the-request) shows how to start such a job through the API.

### Change or turn off idle stop

Set the limit to 4 hours:

```console
$ curl -s -X PATCH "https://api.arvm.dev/v1/machines/calm-river-otter" \
    -H "Authorization: Bearer $ARVM_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{"idle_timeout_seconds": 14400}'
```

Turn idle stop off:

```console
$ curl -s -X PATCH "https://api.arvm.dev/v1/machines/calm-river-otter" \
    -H "Authorization: Bearer $ARVM_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{"idle_timeout_seconds": null}'
```

The shortest limit is 60 seconds. A machine with idle stop off runs, and uses your balance, until you stop it or the balance reaches zero.

## The image

Every machine starts from one image, `ubuntu-24.04`: Ubuntu 24.04 LTS for x86-64.

- systemd is the init system. Units, timers and `cron` work as on any server.
- The login user is `dev`, with `sudo` and no password.
- Docker Engine is installed and running.
- `sshd` is running.


The image also has Docker Compose and Buildx, Git, `build-essential`, Python 3 with `venv` and `pip`, `uv`, Node.js LTS, `bun`, `pnpm`, headless Chromium (`chromium`), `ripgrep`, `jq`, `tmux` and `curl`.

Install anything else with `apt`. What you install stays on the machine's disk across stops.

The image list, with the version new machines get:

```console
$ curl -s "https://api.arvm.dev/v1/images"
```

A machine keeps the image version it was created from. arvm does not update the software in your machine. Run `sudo apt update && sudo apt upgrade` yourself.

## Sizes

| Size | vCPUs | Memory | Disk | Rate | A full month (730 hours) |
|---|---|---|---|---|---|
| `small` | 2 | 4 GB | 51 GB | $0.009 an hour | $6.57 |
| `default` | 4 | 8 GB | 51 GB | $0.018 an hour | $13.14 |
| `large` | 8 | 16 GB | 111 GB | $0.036 an hour | $26.28 |

The disk is thin: it takes space on the server only for what you have written. A larger disk than the size includes is not sold.

## Limits

Your subscription tier sets concurrency and storage limits (`GET /v1/plans` lists every tier, and `GET /v1/billing` returns the active `plan` object for your org). A request that would pass one is refused with `limit_exceeded` (403), naming the limit and its value.

| Limit | Free (`trial`) | Pro (`standard`) | Max (`max`) | Ultra (`ultra`) | Field in `plan` |
|---|---:|---:|---:|---:|---|
| Parallel `default` VMs | 2 | 10 | 50 | 250 | derived from vCPU / RAM |
| vCPUs running at once | 8 | 40 | 200 | 1,000 | `max_running_vcpus` |
| Memory running at once | 16 GB | 80 GB | 400 GB | 2,000 GB | `max_running_memory_bytes` |
| Disk across all machines, running or stopped | 222 GB | 1,530 GB | 7,650 GB | 25,500 GB | `max_disk_bytes` |
| Machines (running or stopped) | 3 | 30 | 150 | 500 | `max_machines` |
| Snapshots | 0 | 20 | 50 | 100 | `max_snapshots` |

A request over a limit fails with `limit_exceeded` and status 403. Limits per request:

| Limit | Value |
|---|---|
| Labels on a machine | 32 |
| Environment variables on a machine | 128, each value at most 32,768 characters |
| SSH keys installed in a machine | 50 |
| Longest `?wait` | 300 seconds |
| Items in one page of a list | 200 |

What a machine cannot do:

- Send mail on TCP port 25. The port is blocked for every machine. Use a mail provider's API or port 587.
- Reach another customer's machine over a private address.
- Use nested virtualization.
- Use a GPU.


## See what happened to a machine

A machine's events are its activity feed, oldest first. Each event has a `type` such as `disk.cloned` or `guest.ready`, a time, and for a step, how long the step took. Some types have `attributes`: a `machine.stop_requested` event that the platform wrote has a `reason`, and a `vm.shutdown` event says whether the machine had to be powered off. [The schema `MachineEventAttributes`](api/schemas.md#machineeventattributes) lists every type and its attributes.

```console
$ arvm events calm-river-otter
```

```console
$ curl -s "https://api.arvm.dev/v1/machines/calm-river-otter/events" \
    -H "Authorization: Bearer $ARVM_API_KEY"
```

Follow the events as they happen. The response is a server-sent event stream that stays open.

```console
$ curl -sN "https://api.arvm.dev/v1/machines/calm-river-otter/events?follow=true" \
    -H "Authorization: Bearer $ARVM_API_KEY"
```

CPU, memory, disk and network use over a time range:

```console
$ curl -s "https://api.arvm.dev/v1/machines/calm-river-otter/metrics?starts_at=2026-11-10T20:00:00Z&ends_at=2026-11-10T21:00:00Z" \
    -H "Authorization: Bearer $ARVM_API_KEY"
```

## When a machine fails

A machine in the phase `failed` has a `failure` object with a `code` and a `message`. The code names what failed, for example `vm_boot_failed`, and the message says in a sentence or two what happened and what to do. Read the machine's events to see the steps before the failure.

The platform stops a machine that fails while you want it running. Its `stop` field has the reason `machine_failed` and the failure. Nothing is billed for a failed machine, and once it is stopped it holds no room on its server.

```json
"desired": "stopped",
"phase": "stopped",
"stop": {"reason": "machine_failed", "at": "2026-11-13T21:00:04Z",
         "failure": {"code": "vm_boot_failed", "message": "The virtual machine did not boot. Restart the machine to try again."}}
```

While the server stops it, the machine is `failed` with its `failure`, and wanted `stopped`. Once the server has stopped it, its phase is `stopped`, or stays `failed` when its disk is lost (`disk_lost`). Either way `stop.failure` says what failed. Start or restart it to try again: like any start, it needs room on its server, and is refused with `no_capacity` until there is some. A machine whose disk is lost (`disk_lost`) stays `failed` and cannot start: delete it, and create a new machine from a snapshot of it if you have one. A machine whose server cannot read the image it boots from (`boot_image_unavailable`) keeps its disk and the data on it: do not delete it. Write to support with its ID. A start boots it once the platform's operators have repaired its server. A machine that was placed on a drive that failed for good before its disk was made held no data, and reads `stopped` with no failure. Its start, restart and snapshot are refused with `machine_has_no_disk` (409), which says so: delete it, and create it again. If a machine with data you need failed, write to <ben@advancedruntime.com> with the `X-Request-Id` of a response and the machine's ID.

[The machines reference](api/machines.md) lists every operation and field.
