---
name: factor-manifest
description: Write or edit a Factor manifest (factory.yaml) to deploy a long-lived GPU machine. Use when the user wants an inference server, an API, a web app or demo reachable from other computers, a dev box, a machine that stays up between runs, deploys from GitHub, or mentions `factor deploy` or factory.yaml.
---

# Writing a Factor manifest

`factory.yaml` describes a **factory** — a machine that stays up between runs
and keeps its disk. `factor deploy` reads it.

If the work has an end (training, a batch job, an experiment), the user wants a
sandbox instead and does not need a manifest. Say so rather than writing one.

## The shape

```yaml
version: 1

hardware: 24gb-class:1
zone: eu
disk_gb: 100

image: python

setup:
  - pip install -r requirements.txt

run: python serve.py

ports:
  - 8000

env:
  MODEL: llama-3.1-8b
  BATCH_SIZE: "8"

secrets:
  - HF_TOKEN

volume:
  out: /factory/out
  local: ./results

idle_timeout: 30m
```

## Every field

| Field | Meaning |
| --- | --- |
| `version` | Always `1`. |
| `hardware` | `24gb-class:1`, `80gb-class:2`. Prefer a class over a model. A new account is limited to one machine at $3/hr. |
| `zone` | A zone, region, country or city. Omit unless the user has a reason. |
| `disk_gb` | Container disk. Raise it for datasets or many checkpoints. |
| `image` | Base image. A published short name — `python`, `server`, `python-cuda`, `server-cuda`, `pytorch`, `cuda` — or the full reference of a public image. Defaults to `python`. |
| `setup` | Shell command lines run as **root** before the workload, again on every start (the disk outside `/workspace` is reset). `&&`, quotes and pipes work. |
| `run` | The workload. Runs as an **unprivileged** user. |
| `ports` | HTTP ports the program listens on that should be reachable from the internet. Each gets a public `https://` address. 1024–65535, at most 5. Factories only. |
| `env` | Plain-text environment variables. Never secrets. |
| `secrets` | Names of stored secrets. Values live in Factor, not the file. |
| `volume.out` | Directory collected as results. Defaults to `/factory/out`. |
| `volume.local` | Local directory to mirror results into. |
| `idle_timeout` | Suspend after this long idle. `0` never suspends. |

## Reachable from anywhere: `ports`

When the user wants the server "public", "visible from any PC", "shareable",
or reachable by a phone, a teammate or another service, **list its port under
`ports:`**. Factor gives each one a public HTTPS address. It is assigned once
the machine is up, a minute or two after `factor deploy` returns; then
`factor info <id>` shows it:

```
Port 8000      https://p8000.38-80-123-24.sslip.io
```

**Do not set up a tunnel** — no `cloudflared`, `ngrok`, `localtunnel`,
`tailscale funnel` or similar, and no `setup:` step installing one. Factor
already provides the address; a tunnel adds a third-party account, a second
thing to keep running, and an address that changes on every restart.

Two things make the address answer:

1. **Listen on `0.0.0.0`, not `127.0.0.1`.** Many frameworks default to
   localhost, which the address cannot reach — it answers **502**. Set the host
   explicitly: `uvicorn app:app --host 0.0.0.0 --port 8000`,
   `flask run --host 0.0.0.0 --port 8000`, Gradio
   `launch(server_name="0.0.0.0", server_port=8000)`, Streamlit
   `--server.address 0.0.0.0 --server.port 8000`, vLLM `--host 0.0.0.0`.
2. **Use a port from 1024 up.** The program runs unprivileged, so 80 and 443
   cannot be bound. 8000, 8080 and 7860 are conventional. The public address is
   HTTPS on 443 regardless of the port inside. Websockets and server-sent
   events work.

The address is live once the program is listening, which takes setup and
model loading — `factor logs <id> -f` shows when. Until then it does not
answer; that is not a misconfiguration yet. `factor info <id> --json` has the
addresses under `endpoints`.

The address is **public**: anyone with it can call the server. If it should
not be open to everyone, have the program check a key (a stored secret, read
from the environment) on each request, and say so to the user.

`ports` is fixed when the factory is created. Adding a port means deploying a
new factory.

## Images

Never write a `dockerfile:` field. Factor does not build images, and a manifest
naming that field is refused. If the user needs their own image, tell them to
build it, push it somewhere public, and put the reference in `image:`.

Prefer `python` and install with `setup:`. It is 103 MB against 4.8 GB for
`pytorch`, and it runs GPU work — torch and jax carry their own CUDA libraries
in their wheels, and the driver comes from the host. A CUDA image is only for
code that wants CUDA from the *system*: compiling a kernel, or a library
linking against a system CUDA.

```yaml
image: python
setup:
  - uv pip install --system torch
```

## Rules that matter

**Never put a secret in `env`.** It is plain text and travels with the file
into the repository. Use `secrets:` and tell the user to store the value:

```bash
printf '%s' "$TOKEN" | factor secret set HF_TOKEN
```

**`setup` is root; `run` is not.** If something in `run` needs a system
package, install it in `setup` — the workload cannot.

**Set an `idle_timeout` unless it serves traffic.** A factory with no timeout
bills until somebody remembers it. `30m` is a reasonable default for a dev box;
`0` is correct for a server.

**A quoted number stays a string.** `BATCH_SIZE: "8"` is deliberate — YAML
would otherwise hand the program an integer where it expects text.

## Deploying

```bash
factor deploy                       # ./factory.yaml
factor deploy ./infra/serve.yaml    # a named file
factor deploy --env .env.local      # per-machine values, encrypted
```

**Each `factor deploy` creates a new factory**, with its own machine, disk and
address. Before deploying again, check `factor ls`: if an earlier one of yours
is still up, tell the user and offer to stop or remove it — two running
factories bill twice. A factory connected to a GitHub repository is instead
redeployed in place by a push, keeping its machine and address.

## Lifecycle, for reference

```bash
factor stop <id>     # suspend; disk kept, compute billing stops
factor start <id>    # resume, disk intact
factor rm <id>       # destroy the machine AND its disk. No undo.
```

Never run `rm` unless the user asked for it in those words.

## Deploying from GitHub

A push can redeploy a factory, but the factory must already exist — a push
never creates a machine. Setting it up is a dashboard task (install the app,
connect the repository to the factory), so hand that to the user rather than
attempting it.
