---
name: factor-debug
description: Diagnose a Factor run that failed, hung, produced no output, or cost more than expected. Use when a `factor` command errors, a machine will not start, logs are empty, results are missing, or the user asks why a run failed.
---

# Diagnosing a Factor run

Work in this order. Most failures are one of the first three and are not
mysterious once you have looked.

## 1. Read what it actually printed

```bash
factor list --all
factor logs <id>
```

Do **not** run `factor rm` on a failed machine before reading its logs. It
destroys the logs and the exit code along with the machine.

A reused sandbox's log holds **every run** on it, oldest first. The latest run
starts at its last `fetching source` line; a traceback above that belongs to an
earlier run, not to the code you just changed. When you ran it yourself with
`--stream`, that output is exactly the latest run.

The state tells you where it got to:

| State | Meaning |
| --- | --- |
| `pending` | Waiting for hardware. Nothing has run. |
| `running` | Setup or your code is executing — or, for a sandbox with an exit code, its program has finished and the machine is **warm**, waiting up to 10 minutes for the next run. Billing as running; `factor stop <id>` ends it early. |
| `suspended` | A sandbox whose program exited (check the exit code), or a stopped factory. Not billing for the GPU. A sandbox suspended **with no exit code** was stopped mid-run, usually because its agent stopped reporting; the reason is printed, the disk is kept, and results sent during the run are already downloadable. |
| `failed` | It stopped in a way nobody asked for. Read the logs and exit code. |
| `terminated` | Deleted, deliberately or by the 7-day sandbox cleanup. With no exit code, it was deleted before the program finished; the CLI exits non-zero and prints the reason. |

A run cut short exits non-zero and says why, for example `the agent stopped
reporting for 5m10s`. If the error says **no machine was started** because the
control plane cannot be reached at its public address, the problem is on
Factor's side, not in your code. Don't retry in a loop; report it.

## 2. The four failures that account for most of them

**Empty logs on a run that is clearly working.** Buffered output. Python needs
`flush=True` or `-u`; nothing is lost, it just has not been written yet.

**"No such file" for something that exists locally.** The folder was uploaded
without it — check `.gitignore`, which is respected on upload. Data files and
model weights are commonly ignored and commonly needed.

**Results missing after `factor pull`.** The code wrote somewhere other than
`/factory/out`. Nothing outside that directory survives the machine.

**"Permission denied" writing outside the workspace.** The workload runs as an
unprivileged user, deliberately. Install packages in `setup` (root), not in the
workload.

**`setup step N exited M; the workload will not run`.** That setup line
failed; its output is just above. Each `--setup` value is one shell command
line, so `apt-get update && apt-get install -y ffmpeg` is fine as one step.

## 3. If it never started

```bash
factor hardware      # is what was asked for actually available?
factor zones
```

| Refusal | What to do |
| --- | --- |
| `limited to $3.00/hr while it is verified` (or another amount) | The account's limit, not a bug. Choose cheaper hardware (`factor hardware`), or the user tops up to raise it. |
| `can run 1 machine(s) at once` | Something is already running: `factor ls`. Wait for it, or ask before stopping it. |
| `no … capacity in <zone>` with alternatives | Every listed alternative is free right now; use one, or a class such as `--gpu 24gb-class`. |
| `verify a card` | The user verifies a card in the dashboard (Billing). You cannot. |

A run stuck `pending` is usually a request nobody can fill — a specific card in
a specific zone. Widen it: a class such as `--gpu 24gb-class` instead of naming a model, or
drop `--zone`.

Also check credit:

```bash
factor billing balance
```

A spend cap that has been reached terminates machines and refuses new ones. The
balance output says so.

## If the public address does not answer

A factory's `ports:` address (`factor info <id>` shows it) answering **502**,
refusing the connection or timing out is almost always one of these, in order:

1. **Still starting.** Setup and model loading come first; `factor logs <id> -f`
   shows when the server says it is listening.
2. **Bound to `127.0.0.1`.** The log line reads `Listening on 127.0.0.1:8000` or
   `localhost:8000`. Make the program listen on `0.0.0.0` and deploy again.
3. **Another port.** The program listens on a port not under `ports:` — compare
   the log line with the manifest.
4. **No address yet.** `factor info <id>` says "assigned once the machine is up"
   until the machine has its public IP; wait and look again.

The fix is never a tunnel (cloudflared, ngrok): the address is right, the
program is not reachable on it.

## 4. If it cost more than expected

```bash
factor stats
factor list --all
```

Look for a **factory** that is still running, or a second sandbox started
while debugging and forgotten. A sandbox stops GPU billing when its program
exits; a factory bills until it is suspended or terminated, and one left
running over a weekend is the usual answer.

```bash
factor stop <id>     # suspend, keep the disk
```

Then add `idle_timeout: 30m` to its manifest so it does not happen twice.

## 5. Errors from the CLI itself

The CLI explains what was wrong with a command and prints the correct usage —
read that before guessing.

| Message | What it means |
| --- | --- |
| `not signed in` | `factor auth login`. Needs a browser, so the user must do it. |
| `credentials file has insecure permissions` | `chmod 600 ~/.factor/credentials` |
| `unknown flag` on a flag that exists | A second, older `factor` earlier on `PATH`. `which -a factor`. |
| `not a member of that team` | Signed in for a different team. `factor team list`, then `factor team use <team>`. |

## What to report back

When you have found it, tell the user the cause and the specific fix — not the
whole transcript. If a machine is still running and costing money, say that
first.
