# Machine

> Machines: an always-on computer for agents that should never sleep.

> [!NOTE]
> Invite-only beta. [Request access](mailto:support@noclick.com?subject=Invite-only%20beta%20access) to use this page's API; without access, a call answers 404, or `not_available`.

```python
box = noclick.Machine.from_name("support-box", create_if_missing=True, size="medium", region="eu",
                                max_monthly_usd=120)
support = noclick.Agent.from_name("support", create_if_missing=True, instructions="...",
                                  harness="claude_code", model_connection="claude", machine=box)
print(box.exec("df -h /").stdout)
```

An agent on a machine runs its harness there instead of in a sandbox per
conversation: nothing is reaped when it goes quiet, and there's no per-minute
sandbox charge, only the machine's flat monthly price. Each conversation gets
its own container on the machine, so threads never see each other's files.
Model and tool calls go through NoClick's credential proxy with temporary keys:
your real keys are never on the machine. NoClick manages its image and updates,
restarts it if it fails (rebuilding it on a new host from its last backup if it
must), and attached volumes outlive it.

A Linux server you run can be one too, free (`Machine.add_own`): run the
command its `pairing` shows on the server as root, and your agents run there
in containers:

```python
home = noclick.Machine.add_own()
print(home.pairing.command)
# curl -fsSL https://api.noclick.com/machine-agent/v1/machine.sh | sudo sh -s -- --code nc_mach_...
```

## Machine (invite-only beta)

```typescript
class Machine
```

Invite-only beta.

An always-on computer of a fixed `size` in one `region`, billed a flat monthly price (a thirtieth
of it a day while it exists, running or stopped). Agents created with `machine` run their harness
on it, each conversation in a container of its own; `exec`, `files` and `expose` reach the
machine itself.

| Attribute | Type | Description |
| --- | --- | --- |
| `id` | `string` |  |
| `name` | `string` |  |
| `kind` | `MachineKind` | `noclick`: a machine NoClick runs; `own`: a server you added. |
| `size` | `MachineSizeName | null` | Null on your own machine, which is the size its server is. |
| `host` | `MachineHostName | null` | The host it runs on, for its life; null on your own. |
| `cpu` | `number | null` | vCPUs (hardware threads). |
| `memoryGb` | `number | null` |  |
| `diskGb` | `number | null` | Its disk. A larger size on Hetzner keeps the disk it had, so a move back down stays a resize. |
| `os` | `string | null` | The server's system, as it reports it (`Ubuntu 24.04.1 LTS`). |
| `hostname` | `string | null` |  |
| `lastSeenAt` | `Date | null` | When it last answered NoClick: on your own machine `offline`, since when. |
| `maxConversations` | `number | null` | Your own machine: the most of its agents' conversations you let work at once (null: what the server takes). |
| `conversationsAtOnce` | `number | null` | How many of its agents' conversations work at once. |
| `agentShare` | `number | null` | Your own machine: the part of its CPUs and memory its agents use (0.75 by default); the rest stays yours. |
| `agentShareFixed` | `boolean | null` | True on a Mac once NoClick's VM is made: a VM keeps its size. |
| `docker` | `boolean` | Your own machine: whether its agents' containers run Docker (any `appTesting` but `never`). |
| `appTesting` | `AppTesting` | Your own machine: whether its agents run apps and test databases (`AppTesting`); `never` on one NoClick runs. |
| `workspaces` | `MachineWorkspaces` | Where each conversation's workspace lives (`MachineWorkspaces`): `saved` on a machine NoClick runs. |
| `agentsEnabled` | `boolean | null` | Whether agents run on machines on this API yet (`Machine.agentsEnabledHere()`). |
| `region` | `RegionName | null` | The region it runs in, fixed when it was created. |
| `status` | `MachineStatus` |  |
| `statusReason` | `string | null` | Why it's stopped or failed, or why it restarted. |
| `monthlyUsd` | `number | null` | What it costs a month, in US dollars, running or stopped (0 for your own). |
| `maxMonthlyUsd` | `number | null` | The most you agreed it may cost a month. |
| `network` | `boolean | string[] | null` | What its own commands may reach: `true` (anywhere the machines usage policy allows) or the hosts. |
| `volumes` | `Record<string, string>` | The volumes it mounts: `{ path: volume id }`. |
| `agentCount` | `number | null` | How many agents run on it. |
| `workingCount` | `number | null` | How many of its agents are working now, from its last check-in. |
| `agentStates` | `MachineAgentState[]` | Each agent on it, `{agent_id, working}`: working while one of its conversations there is. |
| `spentUsdThisMonth` | `number | null` | What it was charged this month (UTC) so far, in US dollars. |
| `startedAt` | `Date | null` | When it last booted, while it runs: its uptime. |
| `pending` | `{ size: MachineSizeName; move: boolean } | null` | While `updating`: the size it becomes, and whether it moves to a new host for it. |
| `image` | `string | null` | The NoClick-managed image it runs, with its harness versions. |
| `restarts` | `number | null` | How many times it restarted after failing, ever. |
| `lastRestartAt` | `Date | null` |  |
| `userId` | `string | null` |  |
| `createdAt` | `Date | null` |  |
| `files` | `MachineFiles` |  |
| `health` | `MachineHealth | null` | How hard it works, from its last check-in while it runs; null otherwise. |
| `ports` | `MachinePort[]` | The ports it serves. |
| `pairing` | `MachinePairing | null` | Your own machine until its server is set up; null after, and on a machine NoClick runs. |
| `consoleUrl` | `string | null` | This machine in the developer console (null off the hosted API). |

Types:

```typescript
/** `noclick`: a machine NoClick runs, at a monthly price. `own`: a server you added, free. */
type MachineKind = "noclick" | "own";

/** `xlarge` is Hetzner's alone, so it runs only in `eu`. */
type MachineSizeName = "small" | "medium" | "large" | "xlarge";

/** The host a machine runs on, for its life. */
type MachineHostName = "hetzner" | "digitalocean";

/**
 * How a coding agent may turn app testing on (Docker in its sandbox, for a task that runs the app or its tests against
 * a real database): `by_itself` turns it on when a task needs it and off once it's done, saying each in its chat;
 * `ask_first` asks the account's owner in the chat each time; `never`.
 */
type AppTesting = "by_itself" | "ask_first" | "never";

/**
 * Where each conversation's workspace (`/workspace`) lives: `local` (your own machine's default: on its disk alone,
 * never saved, so a turn ends without waiting on a save; a conversation that starts elsewhere, or whose agent leaves,
 * starts with an empty one) or `saved` (in NoClick's volumes, saved after every turn; always on a machine NoClick
 * runs).
 */
type MachineWorkspaces = "local" | "saved";

type RegionName = "us-east" | "us-west" | "eu" | "ap" | "in";

/** `awaiting_approval`: rented while NoClick reviews the account's company; it starts once that's approved. */
type MachineStatus =
  | "awaiting_approval" | "provisioning" | "running" | "offline" | "restarting" | "updating" | "stopped" | "failed";

/** Each agent on a machine: working while one of its conversations there is. */
interface MachineAgentState {
  agentId: string;
  working: boolean;
}
```

### Machine.sizes

```typescript
static sizes(
  options?: {
    region?: RegionName;
    includeDominated?: boolean;
    client?: NoClick;
  },
): Promise<MachineSize[]>
```

The sizes worth buying now, smallest first: size first, each at its cheapest anywhere (its `region`, `host`,
`diskGb` and `monthlyUsd`), or as bought in `region` (`regions()`), with every region it can be bought in now,
cheapest first (`regions`). A size that can't be bought now is left out, as is one where another that can be
bought has at least its vCPUs and memory for no more (judged across every region, or in `region`; a larger disk
alone doesn't count); `includeDominated` lists every size, each with `available` and `dominatedBy`.

    const [size] = await Machine.sizes();
    await Machine.create("support-box", { size: size.name, region: size.region!, host: size.host!, maxMonthlyUsd: size.monthlyUsd });

Parameters:

- `options.region` (`RegionName`)
- `options.includeDominated` (`boolean`)
- `options.client` (`NoClick`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.

Returns: Each size's `name` (what `size=` takes), its processors and memory, about how many
conversations can work on it at once, and its cheapest offer now: the `region`, the
`host` it would go on and its `disk_gb` and `monthly_usd` there. `regions` lists every
region it can be bought in now, cheapest first, and `hosts` each host that runs it here.
Stock is read at most a minute before; `create` checks again.

Types:

```typescript
type RegionName = "us-east" | "us-west" | "eu" | "ap" | "in";
```

### Machine.create

```typescript
static create(
  name: string,
  options: MachineCreateOptions & AllowExisting,
): Promise<Machine>
```

Start an always-on machine called `name` (unique to its user; a taken name throws `Conflict`
with `existingId`, or with `allowExisting: true` returns the machine already there, as it is: nothing
about it changes), refused with `PriceExceeded` if its size costs more than `maxMonthlyUsd` on the host it goes
on: the cheapest host with stock for it in its region, or `host` when one is named. An
account's first machine needs its company vetted by NoClick: its owner asks in the developer console
(Resources, Machines), saying what its machines will run, and until NoClick approves it this throws
`ActionRequired`, whose `nextStep` links that page.

Parameters:

- `name` (`string`, required)
- `options.size` (`MachineSizeName`, default `"small"`): One of `Machine.sizes()`; `small` by default.
- `options.region` (`RegionName`): Where it runs (`regions()`), for good; omitted, your account's default region, else `us-east`.
- `options.volumes` (`Record<string, VolumeRef>`): Volumes it attaches, by absolute path: each conversation sees a volume as it was when its turn started
and saves its writes when the turn ends.
- `options.network` (`boolean | string[]`): What the machine's own commands may reach: `true` (anywhere the machines usage policy allows: no mail
ports, mining pools or private addresses) or a list of hosts (HTTPS to them, `"*.github.com"` for
subdomains, and name lookups).
- `options.maxMonthlyUsd` (`number`, required): The most its size may cost a month on the host it goes on; above it nothing starts (`PriceExceeded`, naming the
host and its price when only a dearer host has stock).
- `options.host` (`MachineHostName`): The host to put it on, for its life. Omitted, the cheapest host that runs the size in the region and has stock
(Hetzner in `eu`, DigitalOcean everywhere: `Machine.sizes()`), never one costing more than `maxMonthlyUsd`.
- `options.allowExisting` (`boolean`): A taken name returns the object already there, as it is: nothing about it changes.
- `options.user` (`UserOption`, default: the current user): `undefined` = the ambient user (`asUser`), `null` = the account itself.
- `options.client` (`NoClick`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.

Returns: The machine, `provisioning` until it's ready (`running`).

Types:

```typescript
/** `xlarge` is Hetzner's alone, so it runs only in `eu`. */
type MachineSizeName = "small" | "medium" | "large" | "xlarge";

type RegionName = "us-east" | "us-west" | "eu" | "ap" | "in";

/** A volume to mount: a `Volume`, its id, or its name (the user's own, else the account's). */
type VolumeRef = string | Volume;

/** The host a machine runs on, for its life. */
type MachineHostName = "hetzner" | "digitalocean";

/** `undefined` = the ambient user (from `asUser`), `null` = the account itself. */
type UserOption = UserRef | null | undefined;

/** A `User` or your own id for the user. */
type UserRef = string | UserLike;

/** Anything that can name a user lazily (a `User`). */
interface UserLike {
  _userId(): Promise<string>;
}
```

### Machine.addOwn

```typescript
static addOwn(options?: MachineAddOwnOptions): Promise<Machine>
```

Add a Linux server you run (x86-64 or ARM64, with sudo) as a machine your account's agents run on, in containers:
free, its agents' model calls at cost. Its containers can't reach its network, and on the server itself NoClick
only opens the account owner's `shell` and `files`, as its `noclick` user.
Run `pairing.command` on it as root within 30 minutes; it's `provisioning` until the server answers, then
`running`, and `offline` while it's silent (its agents' turns fail then). Called again before a server pairs,
it returns that same machine, with its code while the code is good and a new one once it expired: add one per
server, after the last one paired. The account's only: not for `asUser`.

Parameters:

- `options.name` (`string`): Omitted, it takes the server's hostname when its installer runs.
- `options.maxConversations` (`number`): How many of its agents' conversations may work at once, at most what the server takes.
- `options.agentShare` (`number`): The part of the server its agents use, 0.1 to 1: 0.75 by default, 1 for a server just for NoClick. On a Mac,
NoClick's VM is made that size.
- `options.docker` (`boolean`): Sent alone, `true` chooses `appTesting: "by_itself"` and `false` `"never"`.
- `options.appTesting` (`AppTesting`): Whether its agents run apps and test databases (`AppTesting`): `ask_first` unless it says (each agent asks its
owner in the chat first). Each conversation's container then runs its own Docker, inside the container's gVisor
sandbox (no host socket, nothing privileged on the server); a container whose agent's network is limited runs
without it. An agent on it gets the stricter of this and its own `appTesting`.
- `options.workspaces` (`MachineWorkspaces`): Where each conversation's workspace lives (`MachineWorkspaces`): `local` unless it says. Either way, a checkout
kept on the server borrows from its repo cache, package managers share their caches, and its volumes are mounted
read-only.
- `options.client` (`NoClick`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.
- `options.user` (`UserOption`): `undefined` = the ambient user (`asUser`), `null` = the account itself.

Returns: The machine, `provisioning` until the server answers, then `running`
(`offline` while it's silent: its agents' turns fail then), with its
`pairing`.

Types:

```typescript
/**
 * How a coding agent may turn app testing on (Docker in its sandbox, for a task that runs the app or its tests against
 * a real database): `by_itself` turns it on when a task needs it and off once it's done, saying each in its chat;
 * `ask_first` asks the account's owner in the chat each time; `never`.
 */
type AppTesting = "by_itself" | "ask_first" | "never";

/**
 * Where each conversation's workspace (`/workspace`) lives: `local` (your own machine's default: on its disk alone,
 * never saved, so a turn ends without waiting on a save; a conversation that starts elsewhere, or whose agent leaves,
 * starts with an empty one) or `saved` (in NoClick's volumes, saved after every turn; always on a machine NoClick
 * runs).
 */
type MachineWorkspaces = "local" | "saved";

/** `undefined` = the ambient user (from `asUser`), `null` = the account itself. */
type UserOption = UserRef | null | undefined;

/** A `User` or your own id for the user. */
type UserRef = string | UserLike;

/** Anything that can name a user lazily (a `User`). */
interface UserLike {
  _userId(): Promise<string>;
}
```

### Machine.agentsEnabledHere

```typescript
static agentsEnabledHere(options?: { client?: NoClick }): Promise<boolean>
```

Whether agents run on machines on this API yet. Until they do, an agent isn't put on a machine and your own
server isn't added (`NotAvailable`), and each machine reads `agentsEnabled` false.

Parameters:

- `options.client` (`NoClick`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.

Returns: True once agents run on machines here.

### Machine.fromName

```typescript
static fromName(
  name: string,
  options?: CallOptions & Partial<MachineCreateOptions> & {
    createIfMissing?: boolean;
  },
): Machine
```

A lazy reference to the machine called `name`. Given fields, it gets the machine and sets the `size`,
`volumes`, `network` and `maxMonthlyUsd` you pass, on every run (a new size restarts it, judged
against the `maxMonthlyUsd` set with it). Fields left out are never changed. Its `region` and `host` are
fixed: an existing machine in another throws `Conflict` naming it. `createIfMissing` (with `maxMonthlyUsd`)
starts it when there's none; without it, a missing machine throws `NotFound`.

Parameters:

- `name` (`string`, required)
- `options.createIfMissing` (`boolean`)
- `options.size` (`MachineSizeName`): One of `Machine.sizes()`; `small` by default.
- `options.region` (`RegionName`): Where it runs (`regions()`), for good; omitted, your account's default region, else `us-east`.
- `options.volumes` (`Record<string, VolumeRef>`): Volumes it attaches, by absolute path: each conversation sees a volume as it was when its turn started
and saves its writes when the turn ends.
- `options.network` (`boolean | string[]`): What the machine's own commands may reach: `true` (anywhere the machines usage policy allows: no mail
ports, mining pools or private addresses) or a list of hosts (HTTPS to them, `"*.github.com"` for
subdomains, and name lookups).
- `options.maxMonthlyUsd` (`number`): The most its size may cost a month on the host it goes on; above it nothing starts (`PriceExceeded`, naming the
host and its price when only a dearer host has stock).
- `options.host` (`MachineHostName`): The host to put it on, for its life. Omitted, the cheapest host that runs the size in the region and has stock
(Hetzner in `eu`, DigitalOcean everywhere: `Machine.sizes()`), never one costing more than `maxMonthlyUsd`.
- `options.user` (`UserOption`, default: the current user): `undefined` = the ambient user (`asUser`), `null` = the account itself.
- `options.client` (`NoClick`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.

Returns: A machine that loads (or is started, or has your fields set) the first time it's used.
Nothing is sent yet.

Types:

```typescript
/** `undefined` = the ambient user (from `asUser`), `null` = the account itself. */
type UserOption = UserRef | null | undefined;

/** A `User` or your own id for the user. */
type UserRef = string | UserLike;

/** Anything that can name a user lazily (a `User`). */
interface UserLike {
  _userId(): Promise<string>;
}

/** `xlarge` is Hetzner's alone, so it runs only in `eu`. */
type MachineSizeName = "small" | "medium" | "large" | "xlarge";

type RegionName = "us-east" | "us-west" | "eu" | "ap" | "in";

/** A volume to mount: a `Volume`, its id, or its name (the user's own, else the account's). */
type VolumeRef = string | Volume;

/** The host a machine runs on, for its life. */
type MachineHostName = "hetzner" | "digitalocean";
```

### Machine.fromId

```typescript
static fromId(machineId: string, options?: CallOptions): Machine
```

A lazy reference to a machine by id.

Parameters:

- `machineId` (`string`, required)
- `options.client` (`NoClick`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.
- `options.user` (`UserOption`, default: the current user): `undefined` = the ambient user (`asUser`), `null` = the account itself.

Returns: A machine that loads the first time you read a field. Nothing is sent yet.

Types:

```typescript
/** `undefined` = the ambient user (from `asUser`), `null` = the account itself. */
type UserOption = UserRef | null | undefined;

/** A `User` or your own id for the user. */
type UserRef = string | UserLike;

/** Anything that can name a user lazily (a `User`). */
interface UserLike {
  _userId(): Promise<string>;
}
```

### Machine.get

```typescript
static get(machineId: string, options?: CallOptions): Promise<Machine>
```

Load a machine by id now; an unknown id raises `noclick.NotFound`.

Parameters:

- `machineId` (`string`, required)
- `options.user` (`UserOption`, default: the current user): `undefined` = the ambient user (`asUser`), `null` = the account itself.
- `options.client` (`NoClick`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.

Returns: The machine, loaded.

Types:

```typescript
/** `undefined` = the ambient user (from `asUser`), `null` = the account itself. */
type UserOption = UserRef | null | undefined;

/** A `User` or your own id for the user. */
type UserRef = string | UserLike;

/** Anything that can name a user lazily (a `User`). */
interface UserLike {
  _userId(): Promise<string>;
}
```

### Machine.list

```typescript
static list(
  options?: ReadOptions & { limit?: number; kind?: MachineKind },
): Promise<Machine[]>
```

The current user's machines (the account's own outside `asUser`, or those `userFilter` covers); `kind` narrows them.

Parameters:

- `options.kind` (`MachineKind`)
- `options.limit` (`number`): Return at most this many.
- `options.userFilter` (`UserFilter`): Which users the read covers (`user_id` query), instead of acting as one (`user`).
- `options.user` (`UserOption`, default: the current user): `undefined` = the ambient user (`asUser`), `null` = the account itself.
- `options.client` (`NoClick`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.

Returns: Every matching machine, newest first, fetched page by page.

Types:

```typescript
/**
 * Which users a read covers: `ALL_USERS`, `NO_USER`, a `User` or your id for one. Sent as the
 * `user_id` query parameter, never as the `NoClick-User` header, so it filters without acting as the user.
 */
type UserFilter = typeof ALL_USERS | typeof NO_USER | UserRef;

/** A `User` or your own id for the user. */
type UserRef = string | UserLike;

/** Anything that can name a user lazily (a `User`). */
interface UserLike {
  _userId(): Promise<string>;
}

/** `undefined` = the ambient user (from `asUser`), `null` = the account itself. */
type UserOption = UserRef | null | undefined;

/** `noclick`: a machine NoClick runs, at a monthly price. `own`: a server you added, free. */
type MachineKind = "noclick" | "own";
```

### Machine.listPage

```typescript
static listPage(
  options?: ReadOptions & PageOptions & { kind?: MachineKind },
): Promise<Page<Machine>>
```

One page of machines; pass `nextCursor` back as `cursor`.

Parameters:

- `options.kind` (`MachineKind`)
- `options.cursor` (`string | null`): The `next_cursor` of the page before; omit it for the first page.
- `options.limit` (`number`): Return at most this many.
- `options.userFilter` (`UserFilter`): Which users the read covers (`user_id` query), instead of acting as one (`user`).
- `options.user` (`UserOption`, default: the current user): `undefined` = the ambient user (`asUser`), `null` = the account itself.
- `options.client` (`NoClick`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.

Returns: A page whose `data` holds the machines and whose `next_cursor` is `None` on the last page.

Types:

```typescript
/**
 * Which users a read covers: `ALL_USERS`, `NO_USER`, a `User` or your id for one. Sent as the
 * `user_id` query parameter, never as the `NoClick-User` header, so it filters without acting as the user.
 */
type UserFilter = typeof ALL_USERS | typeof NO_USER | UserRef;

/** A `User` or your own id for the user. */
type UserRef = string | UserLike;

/** Anything that can name a user lazily (a `User`). */
interface UserLike {
  _userId(): Promise<string>;
}

/** `undefined` = the ambient user (from `asUser`), `null` = the account itself. */
type UserOption = UserRef | null | undefined;

/** `noclick`: a machine NoClick runs, at a monthly price. `own`: a server you added, free. */
type MachineKind = "noclick" | "own";
```

### Machine.exec

```typescript
exec(
  command: string,
  options: ExecOptions & { background: true },
): Promise<Operation<ExecResult>>
exec(
  command: string,
  options?: ExecOptions & { background?: false },
): Promise<ExecResult>
```

Run a shell command on the machine itself (not in a conversation's container): `timeoutS` is 60
by default, at most 90; `{ background: true }` returns an `Operation`, for up to an hour.

Parameters:

- `command` (`string`, required)
- `options.background` (`boolean`, required): Return at once with an `Operation` whose `wait()` resolves to the `ExecResult`.
- `options.timeoutS` (`number`): Seconds before the command is stopped: 60 by default, at most 90, or 3600 with `background`.

Returns: What the command printed and how it exited, or with `background=True` an `Operation`
whose `wait()` gives that result.

### Machine.expose

```typescript
expose(port: number, options?: { public?: boolean }): Promise<MachinePort>
```

Serve `port` at an HTTPS URL on NoClick's domain: private (an API key with the `machines` scope, which the
app never sees) unless `public`.

Parameters:

- `port` (`number`, required)
- `options.public` (`boolean`, default `false`)

Returns: The port's `url`.

### Machine.closePort

```typescript
closePort(port: number): Promise<void>
```

Stop serving `port`; its URL stops answering.

Parameters:

- `port` (`number`, required)

### Machine.agents

```typescript
agents(): Promise<JsonObject[]>
```

The agents that run on it, as their API rows (`Agent.fromId(row.id)` for the object).

Returns: Each `Agent`, loaded.

Types:

```typescript
type JsonObject = { [key: string]: unknown };
```

### Machine.update

```typescript
update(
  changes: {
    name?: string;
    size?: MachineSizeName;
    volumes?: Record<string, VolumeRef>;
    network?: boolean | string[];
    maxMonthlyUsd?: number;
    maxConversations?: number | null;
    agentShare?: number | null;
    docker?: boolean;
    appTesting?: AppTesting;
    workspaces?: MachineWorkspaces;;
  },
): Promise<this>
```

Rename it, change its size, volumes, network or price ceiling. New volumes and network apply without a
restart (each conversation's from its next turn). A larger size restarts it once running turns finish
(`updating`); the new price, its host's, applies from the next day. A size stays on the machine's host. A
smaller disk moves a running machine to a new host (a larger size on Hetzner keeps its disk, so moving back
down stays a resize), since no host shrinks a disk in place: its user's home is copied over and each conversation loads its files
from where they're saved, a longer restart (what's on its disk must fit the smaller one; a move that fails
leaves it on its old host). Your own machine takes `maxConversations`, `agentShare`, `appTesting`, `docker` and
`workspaces` instead of a size or a price; its server takes them within seconds, each conversation's container at
its next start.

Parameters:

- `changes` (`{ name?: string; size?: MachineSizeName; volumes?: Record<string, VolumeRef>; network?: boolean | string[]; maxMonthlyUsd?: number; maxConversations?: number | null; agentShare?: number | null; docker?: boolean; appTesting?: AppTesting; workspaces?: MachineWorkspaces; }`, required)

Returns: This machine, updated.

Types:

```typescript
/** `xlarge` is Hetzner's alone, so it runs only in `eu`. */
type MachineSizeName = "small" | "medium" | "large" | "xlarge";

/** A volume to mount: a `Volume`, its id, or its name (the user's own, else the account's). */
type VolumeRef = string | Volume;

/**
 * How a coding agent may turn app testing on (Docker in its sandbox, for a task that runs the app or its tests against
 * a real database): `by_itself` turns it on when a task needs it and off once it's done, saying each in its chat;
 * `ask_first` asks the account's owner in the chat each time; `never`.
 */
type AppTesting = "by_itself" | "ask_first" | "never";

/**
 * Where each conversation's workspace (`/workspace`) lives: `local` (your own machine's default: on its disk alone,
 * never saved, so a turn ends without waiting on a save; a conversation that starts elsewhere, or whose agent leaves,
 * starts with an empty one) or `saved` (in NoClick's volumes, saved after every turn; always on a machine NoClick
 * runs).
 */
type MachineWorkspaces = "local" | "saved";
```

### Machine.newPairingCode

```typescript
newPairingCode(): Promise<this>
```

Your own machine, until its server is set up: a new code (and command) in place of the last one.

Returns: This machine, with the new `pairing`.

### Machine.restart

```typescript
restart(): Promise<Operation<Machine>>
```

Restart it now (running turns fail as interrupted); its disk and volumes are kept and a `machine.restarted`
event follows. Resolves to the machine.

Returns: An `Operation` whose `wait()` gives the machine, `running` again.

### Machine.stop

```typescript
stop(): Promise<this>
```

Stop it: its agents take no turns until `start()`. It's still charged.

Returns: This machine, `stopped`.

### Machine.start

```typescript
start(): Promise<this>
```

Start a stopped machine. One stopped because the balance couldn't pay it is charged what it owes first
(`PaymentRequired` while it can't).

Returns: This machine, `provisioning` until it's `running`.

### Machine.shell

```typescript
shell(): Promise<MachineShell>
```

Open a shell (`bash -l`) on this machine, as its user, in its home: for the account's owner, with its secret key
or signed in, while it's running. Your own machine's too (on a Mac, in NoClick's VM there). Hand `url` and `token`
to a browser terminal: `new TerminalConnection(shell.url, shell.token, { renew: async () => (await
machine.shell()).token })` renews it in place (with no `renew`, it has no lifetime).

Returns: The websocket's `url` and its single-use `token` (good for two minutes): hand them to a browser
terminal (xterm.js) from your server.

### Machine.delete

```typescript
delete(): Promise<void>
```

Delete it with its disk (attached volumes stay); the agents on it go back to their own cloud sandboxes first,
each from its next turn. Your own machine is removed from NoClick, which uninstalls itself from the server when
it next answers.

## MachineSize (invite-only beta)

```typescript
interface MachineSize
```

Invite-only beta. One of `Machine.sizes()`: its processors and memory, and how it's bought now. `region`, `host`,
`diskGb` and `monthlyUsd` are its cheapest offer anywhere (or, asked about a region, there); `regions` lists every
region it can be bought in now, cheapest first, and `hosts` each host that runs it. Stock is read at most a minute
before; `create` checks again, so pass `region`, `host` and `monthlyUsd` (as `maxMonthlyUsd`) to buy exactly this.

| Attribute | Type | Description |
| --- | --- | --- |
| `name` | `MachineSizeName` | What `size=` takes: `small`, `medium`, `large` or `xlarge` (Hetzner's alone, so in `eu` only). |
| `cpu` | `number` | vCPUs (hardware threads), as hosts sell them. |
| `memoryGb` | `number` |  |
| `diskGb` | `number` | The machine's own disk on `host` (while it isn't available, on the first host that sells it). |
| `monthlyUsd` | `number` | Its price per month in US dollars on `host` in `region` (while it isn't available, the price it has once the first host that sells it has one again). |
| `workingConversations` | `number` | About how many coding-agent conversations can work on it at the same moment. |
| `available` | `boolean` | Whether it can be bought now (only false with `includeDominated`). |
| `region` | `RegionName | null` | Where it's cheapest now (your account's default region first at one price), or the region asked about; null when it can't be bought anywhere. |
| `host` | `MachineHostName | null` | The host a new one would go on there now; null while it can't be bought. |
| `dominatedBy` | `MachineSizeName | null` | A size that can be bought now with at least its vCPUs and memory for no more (only listed with `includeDominated`). |
| `regions` | `MachineSizeRegion[]` | Each region it can be bought in now, cheapest first: the host, disk and price there. |
| `hosts` | `MachineHost[]` | Each host that runs it, cheapest first: its regions, disk and price there. |
| `raw` | `JsonObject` | The response JSON exactly as the API sent it. |

Types:

```typescript
/** `xlarge` is Hetzner's alone, so it runs only in `eu`. */
type MachineSizeName = "small" | "medium" | "large" | "xlarge";

type RegionName = "us-east" | "us-west" | "eu" | "ap" | "in";

/** The host a machine runs on, for its life. */
type MachineHostName = "hetzner" | "digitalocean";

type JsonObject = { [key: string]: unknown };
```

## MachineSizeRegion (invite-only beta)

```typescript
interface MachineSizeRegion
```

Invite-only beta. A region a size can be bought in now (`MachineSize.regions`, cheapest first): the host a new one
would go on there, and its disk and flat monthly price there.

| Attribute | Type | Description |
| --- | --- | --- |
| `region` | `RegionName` | What `create` takes as `region`. |
| `host` | `MachineHostName` | The host a new one would go on there now: what `create` takes as `host`. |
| `diskGb` | `number` | Its disk on that host. |
| `monthlyUsd` | `number` | Its price per month in US dollars on that host: what `create` takes as `maxMonthlyUsd`. |
| `dominatedBy` | `MachineSizeName | null` | A size that can be bought there now with at least its vCPUs and memory for no more, which makes this one no buy there (only listed with `includeDominated`). |

Types:

```typescript
type RegionName = "us-east" | "us-west" | "eu" | "ap" | "in";

/** The host a machine runs on, for its life. */
type MachineHostName = "hetzner" | "digitalocean";

/** `xlarge` is Hetzner's alone, so it runs only in `eu`. */
type MachineSizeName = "small" | "medium" | "large" | "xlarge";
```

## MachineHost (invite-only beta)

```typescript
interface MachineHost
```

Invite-only beta. A size on one host (`MachineSize.hosts`): where it runs, its disk there and its price there.

| Attribute | Type | Description |
| --- | --- | --- |
| `host` | `MachineHostName` | What `host=` takes: `hetzner` or `digitalocean`. |
| `regions` | `RegionName[]` | The regions it runs in on this host (`regions()`). |
| `diskGb` | `number` |  |
| `monthlyUsd` | `number` | Its price per month in US dollars on this host, whatever it runs and whether it's busy. |

Types:

```typescript
/** The host a machine runs on, for its life. */
type MachineHostName = "hetzner" | "digitalocean";

type RegionName = "us-east" | "us-west" | "eu" | "ap" | "in";
```

## MachinePort (invite-only beta)

```typescript
interface MachinePort
```

Invite-only beta. A port a machine serves; a private one asks for an API key with the `machines`
scope, a public one answers anyone.

| Attribute | Type | Description |
| --- | --- | --- |
| `port` | `number` |  |
| `url` | `string` |  |
| `public` | `boolean` |  |
| `raw` | `JsonObject` | The response JSON exactly as the API sent it. |

Types:

```typescript
type JsonObject = { [key: string]: unknown };
```

## MachinePairing (invite-only beta)

```typescript
interface MachinePairing
```

Your own machine until its server is set up: the one-time code (and the command carrying it), which NoClick
only shows as it makes it, so a machine read again has `code` and `command` null.

| Attribute | Type | Description |
| --- | --- | --- |
| `code` | `string | null` |  |
| `command` | `string | null` | What to run on the server as root (a Linux server's, or a Linux distro's in WSL on Windows). |
| `expiresAt` | `Date | null` | When the code stops working (30 minutes after it was made); `newPairingCode()` makes another. |
| `installingOn` | `string | null` | The server being set up with the code, once its installer started. |
| `raw` | `JsonObject` | The response JSON exactly as the API sent it. |
| `refused` | `MachineRefusal | null` | The last server turned away with the code, and why (null since the code was made, or once one pairs). |
| `commands` | `{ linux: string; mac: string; linuxUnattended: string; macUnattended: string } | null` | The command for each system: `linux` (`command`) and `mac`, run in Terminal as you, never root; and each with `--yes` to install unattended (SSH, cloud-init, a script): `linuxUnattended`, `macUnattended`. |

Types:

```typescript
type JsonObject = { [key: string]: unknown };
```

## MachineRefusal (invite-only beta)

```typescript
interface MachineRefusal
```

A server turned away with your own machine's code: by NoClick (its system, or the code expired) or by the
installer itself. Cleared by a new code or a server that pairs.

| Attribute | Type | Description |
| --- | --- | --- |
| `system` | `string | null` |  |
| `arch` | `string | null` |  |
| `hostname` | `string | null` |  |
| `message` | `string` | What the server's terminal printed, whole. |
| `nextStep` | `string | null` | What to do, where NoClick knows it. |
| `at` | `Date | null` |  |
| `raw` | `JsonObject` | The response JSON exactly as the API sent it. |

Types:

```typescript
type JsonObject = { [key: string]: unknown };
```

## MachineFiles (invite-only beta)

```typescript
class MachineFiles
```

Invite-only beta. `machine.files`: read and write files on the machine's own disk.

### MachineFiles.write

```typescript
write(
  path: string,
  data: string | Uint8Array | ArrayBuffer | Blob,
): Promise<void>
```

Write `data` (bytes, or text as UTF-8) to `path` (relative paths are under `/home/noclick`).

Parameters:

- `path` (`string`, required)
- `data` (`string | Uint8Array | ArrayBuffer | Blob`, required)

### MachineFiles.read

```typescript
read(path: string): Promise<Uint8Array>
```

Read the file at `path`; a missing file raises `noclick.NotFound`.

Parameters:

- `path` (`string`, required)

Returns: The file's bytes, exactly as stored.

### MachineFiles.list

```typescript
list(path?): Promise<MachineFileEntry[]>
```

The files and folders in the folder at `path` (relative paths are under `/home/noclick`), by name.

Parameters:

- `path` (`string`, default `"/home/noclick"`)

Returns: Each entry's `path`, `type` (`file` or `directory`), `size` and `updated_at`.

## MachineFileEntry (invite-only beta)

```typescript
interface MachineFileEntry
```

A file or folder on a machine's disk (`machine.files.list`).

| Attribute | Type | Description |
| --- | --- | --- |
| `path` | `string` |  |
| `type` | `"file" | "directory"` | `file` or `directory`. |
| `size` | `number | null` | A file's bytes (null for a folder). |
| `updatedAt` | `Date | null` |  |

## MachineHealth (invite-only beta)

```typescript
interface MachineHealth
```

How hard a running machine works, from its last check-in (`machine.lastSeenAt`).

| Attribute | Type | Description |
| --- | --- | --- |
| `cpus` | `number | null` | Its vCPUs (your own: the server's). |
| `load1m` | `number` | Its one-minute load average, and that as a part of its vCPUs kept busy (at most 100). |
| `cpuPercent` | `number | null` |  |
| `memoryUsedGb` | `number` | Memory in use and in all (your own: the whole server's; its agents use `agentShare` of it). |
| `memoryTotalGb` | `number` |  |
| `diskUsedGb` | `number` |  |
| `diskTotalGb` | `number` |  |

## MachineShell (invite-only beta)

```typescript
interface MachineShell
```

A shell on a machine NoClick runs (`machine.shell()`): `url` is a websocket, opened once with `token` within two
minutes, whose first message is `{"type": "auth", token, cols, rows}`; then binary messages carry what you type and
what it prints, a text `{"type": "resize", cols, rows}` sizes it, and it closes (code 4410) once bash exits, after
`idleLimitS` with nothing typed, or when the socket closes.

| Attribute | Type | Description |
| --- | --- | --- |
| `machineId` | `string` |  |
| `url` | `string` |  |
| `token` | `string` |  |
| `tokenExpiresAt` | `Date | null` |  |
| `idleLimitS` | `number` |  |
