# Machines

A machine is a Linux computer you start, use and delete with `thz`. Commands run as the user `user` in `/home/user`. Every command takes `--json`, and its output is then one JSON value on stdout. The service address is https://app.thaloz.ai, and `thz` reads it from `THZ_API_URL`.

## Sizes

| Size | vCPU | Memory | Disk | Price per hour |
|---|---|---|---|---|
| `small` | 2 | 4 GB | 25 GB | $0.018 |
| `default` | 4 | 8 GB | 50 GB | $0.036 |
| `large` | 8 | 16 GB | 100 GB | $0.072 |

A `default` machine is ready fastest. `small` and `large` take a few seconds longer to start.

## Commands

| Command | What it does |
|---|---|
| `thz new [--name NAME] [--size SIZE] [--env NAME=VALUE] [--stop-after TIME] [--shell]` | Starts a machine and waits until it is ready. |
| `thz ls` | Lists the machines you keep, running and stopped. |
| `thz get MACHINE` | Shows one machine. |
| `thz exec MACHINE -- 'SCRIPT'` | Runs a shell script in a running machine and exits with its exit code. |
| `thz shell MACHINE` | Opens an interactive shell. It needs a terminal. |
| `thz cp SOURCE TARGET` | Copies a file or directory in or out. Write a machine's path as `NAME:PATH`. On Windows `C:\x` is a local path, so give a machine with a one-letter name by its ID. |
| `thz stop MACHINE` | Stops a machine and keeps its disk. |
| `thz resume MACHINE [--stop-after TIME]` | Starts a stopped machine again from its disk. |
| `thz extend MACHINE TIME` | Sets a running machine to stop `TIME` from now, as in `1h`, or `never`. |
| `thz rm MACHINE --yes` | Deletes a machine and its disk. |
| `thz run [--push DIR] [--timeout TIME] -- COMMAND` | Starts a machine, runs one command, deletes the machine, and exits with the command's code. |
| `thz usage` | Shows this period's machine time and cost per machine. |
| `thz limits` | Shows starts used and what the next start costs. |
| `thz wallet` | Shows the wallet balance and its movements. |
| `thz whoami` | Shows the account, its state and the key's preset. |

`MACHINE` is the machine's name or its ID. A name holds a-z, 0-9 and `-`, starts with a letter, and is unique among the machines you keep. An ID always holds `_`.

## A whole task

```sh
thz new --name task-1 --json
thz cp ./src task-1:/home/user/ --json
thz exec task-1 --json -- 'cd src && make test'
thz cp task-1:/home/user/src/out.log ./out.log --json
thz rm task-1 --yes --json
```

For a one-off job, `thz run` does the same in one command:

```sh
thz run --push . --timeout 20m -- make test
```

`--push DIR` uploads the directory without the files git ignores, and the command starts in `/home/user`, where the files are.

## Command output

`thz exec --json` prints `stdout`, `stderr`, `exitCode`, `truncated` and, when the timeout ended the command, `timedOut: true`. `thz exec` and `thz run` exit with the command's own exit code. Output over 1 MiB is cut, and `truncated` is `true`. With `--json`, an `error` field tells a service error apart from a command that exited with the same number.

## States

A machine is `starting`, `running`, `stopping`, `stopped` or `error`. A deleted machine is gone. `thz get --json` also shows `readyAt`, `stoppingAt`, `stopReason`, `autoStopAt` and `cost`, the list price of the current or last run.

A machine stops for one of these reasons: `user`, `auto_stop`, `wallet_empty`, `plan_ended`, `suspended` or `host_maintenance`.

## Auto-stop

A machine stops 30 minutes after it starts or resumes. Pass `--stop-after` to `thz new` or `thz resume`, from `1m` to `30d`, or `never`. Run `thz extend` to move the stop of a running machine. Billing ends when the stop begins.

## Stopped machines

A stopped machine costs nothing. Its disk is kept for 14 days after the stop, and `thz resume` brings back its files. Running processes do not survive a stop. After 14 days, `thz resume` fails with `disk_expired`.

## Limits

You can run 100 machines at once and keep 200, running and stopped together. `thz limits` shows your account's numbers, which can be lower if we lowered them for your account. Past those, a start fails with `running_limit_reached` or `machine_limit_reached`. Starts per minute, hour and day are in [Billing](/docs/billing.md).
