# How a Computer sleeps, wakes and stops

> When a Computer goes idle, what wakes it, what survives sleep and Stop, what Keep awake does, and the running limits and command times that apply.

A hosted Computer has two parts with different lifetimes. Its **files** are
saved and stay put. Its **running machine** starts on demand, runs your
commands, and ends. This page covers when the machine ends, what starts it
again, and what you lose and keep.

## States

A Computer reads as one of these:

- **Sleeping.** No machine is running. Files are saved.
- **Queued.** The start is waiting for a free host or a free slot. A busy host
  shows your position.
- **Starting.** The machine is booting.
- **Running.** The machine is up.

Reading the state never wakes a sleeping Computer.

## Idle timeout

A running Computer sleeps after **one hour** with no activity. These count as
activity:

- a command starting or finishing;
- terminal traffic, and traffic through an exposed port preview.

An open terminal or connection that sends nothing does not count. Idle time is
measured from the last real traffic.

When the hour passes, the machine is destroyed. Any command still running ends
with it, and its process record says it ended on idle sleep.

Metering follows the same rule. Without Keep awake, billing stops at the last
activity, so the idle hour is never charged.

## What wakes a Computer

Starting is automatic. The next thing that needs a machine starts one:

- the **Start** control on the Computer;
- a command an Agent or App runs on it;
- a background process an Agent starts with `start_process`;
- a terminal opened in Shed.

A start needs a free running slot for your Team (see
[Running limits](#running-limits)) and available host capacity. A queued start
that is still waiting after 30 minutes fails.

Reading a file does not start the machine. The saved copy answers the read.

## What persists

| Item                                 | Across sleep and Stop                           |
| ------------------------------------ | ----------------------------------------------- |
| Saved workspace files                | Kept. The next start puts them back.            |
| The Computer itself and its settings | Kept, including Keep awake and Internet access. |
| Running processes and commands       | Ended. They do not return when it wakes.        |
| Output of a background process       | Kept, bounded to its last 200 lines.            |
| The process record and why it ended  | Kept.                                           |

After a Computer wakes, check the process list and start again whatever you need
running. Keep your own backup or version-controlled copy of important work.

## Keep awake

Keep awake is a per-Computer switch, off by default. With it on, the Computer
does not sleep when idle. A Computer that stays running keeps counting toward
your Team's running limit.

- On a host that bills for idle time, the idle time is charged.
- It does not lift the **24 hour** awake ceiling listed in
  [Limits](/account/limits/).
- Turn it on for work that must continue without commands, such as a long
  background process.

The setting belongs to the Computer. Find it on the Computers page in Fungi and
in Oyster.

## Stop

The owner can stop a running Computer on purpose. **Stop** is on the Computer's
row in Oyster's Computers page, and on its card in the Hub's Computers page. It
asks first: "Running commands end; files are kept."

Stop does three things:

1. Copies the running machine's file changes back into the saved workspace.
2. Destroys the machine.
3. Marks running commands as ended, like an idle sleep.

The Computer then reads as sleeping. Press **Start**, or run any command, to
bring it back.

If the Computer is booting or has a command in flight, Stop is refused so it
does not cut the work off. Try again when it settles. In the Hub, a busy
Computer answers with a short message, and the Computer keeps running.

Stop frees a running slot and ends the machine now. It does not delete the
Computer, and it is not a lock: a later command wakes it again.

## Running limits

A Team on the Free plan can have **2** hosted Computers running at once, and
**1** until it adds a payment method in Billing. A Pro Team can have **25**.
This counts running Computers, not how many you own. A sleeping Computer does
not count.

When a Team is at its limit, a new start is refused until another Computer
sleeps or stops. If the host itself is full, the start is queued and shows its
position.

These limits are for Fungi's hosted Teams. A self-hosted Oyster sets no per-Team
running limit in its own code.

## Commands and background processes

A single command that you wait for can run up to **ten minutes**. Asking for
longer is refused with that limit.

Work that needs longer runs as a **background process**. It returns an id at
once and has no run-time limit of its own, but it lives only while the Computer
is awake. It ends if the Computer sleeps or stops. An Agent reads its output
with `process_logs`, waits with `wait_process` (each wait is at most ten
minutes, and it returns early with `timedOut` set so the Agent can call again),
and ends it with `kill_process`.

A Computer keeps up to 16 running processes and 64 records.

For a process that must outlast an idle hour, turn on Keep awake.

## Where next

- [Use Computers](/guides/use-computers/) covers running commands and previews.
- [Limits](/account/limits/) lists every Computer limit in one place.
- [Billing](/account/billing/#computer-sizes-and-prices) has prices by size.
