# What does the shell toolkit do?

**The `shell` toolkit runs commands in a real terminal on your computer, one that remembers. Each chat keeps one terminal alive, so a folder change, an exported variable or an activated environment is still there for the next command. Servers run in the background and report back when they finish, and on macOS every command runs inside a sandbox that walls off your credentials.**

---

## What makes it different

| what it does | the primitive behind it | what that buys you |
|---|---|---|
| **A terminal that remembers** | One live `bash` per chat, not a fresh shell per command | `cd`, `export` and `source .venv/bin/activate` carry over. No more `cd X && source Y && do Z` on every call |
| **Timeouts don't cost your setup** | On a timeout it kills what the command started, deepest first, and keeps the shell | A hung `npm install` doesn't wipe your exported variables |
| **Stop means stop** | Stopping a turn interrupts the running command and abandons its remaining steps | `render; upload` won't upload after you stopped the render |
| **Servers run in the background** | Dev servers (`npm start`, `vite`, `uvicorn`, `streamlit`, `python -m http.server`…) start as background jobs automatically | The chat keeps going, and the job posts its last output back when it finishes |
| **A real sandbox** | On macOS every command runs through the system sandbox: Irene's keys are blocked outright, and `~/.ssh`, `~/.aws`, `.env` files and similar need your approval | A command can't quietly read your credentials |
| **Big output stays out of the chat** | Large output is stored on disk behind a pointer; search-style commands (`grep`, `find`, `tail`) are stored sooner | The agent almost never needs to read stored command output back, so moving it out is nearly free |

---

## How it works

### The persistent terminal

- **One `bash` per chat** (up to 24 alive at once; the idlest is retired first). A dead one is restarted transparently.
- **Each command reports its exit code and folder** through a unique marker, so the agent always knows whether it worked and where it is. **Why a marker:** a terminal never says "done". The marker is fresh every time, so a command that prints an old one can't confuse it.
- **Programs can't swallow the terminal.** Each command's input is closed. **Why:** a program that reads input (like ffmpeg) once ate the markers, and a finished render waited out the whole timeout.
- **A `cd` moves the terminal only.** Moving the chat's file folder (`change_workspace`) moves the terminal with it.
- **`cwd=` runs one command elsewhere** in a sub-shell, without moving the terminal's home.
- **An `exit`** ends the terminal. A fresh one starts, and the reply says what was lost.

### Timeouts and stopping

- **Default timeout: 30 seconds,** longer on request.
- **On a timeout:** everything the command started is killed, deepest first, and the terminal is kept with your variables intact. Only if it won't let go within 3 seconds is the terminal replaced. The reply says which happened ("exports still set" or "exports gone").
- **Stopping a turn** interrupts the running command and abandons any later steps in it. It only kills processes this command started, never a server you started earlier.
- **Output cap:** 2 MB per stream per command. If it's hit, the reply says so.

### Background jobs

- **`background=True`**, or a recognised server command, starts a background job. You get a job id and process id right away.
- **When it finishes,** its last 8 KB of output is posted into the chat, and an idle chat wakes up to tell you.
- **Logs** are kept in `~/.irene/coding_jobs/`.
- **If Irene restarts** while a job is running, the job's report is lost. On the next start, leftover jobs are stopped and marked *interrupted*. A process id is checked against its command first, so an unrelated process is never killed.

### The sandbox

| where | wall |
|---|---|
| **macOS** | every command runs through the system sandbox. Irene's own keys and connections are denied outright; `~/.ssh`, `~/.aws`, gcloud, `.netrc`, Docker and Kubernetes config and any `.env` file need a one-time approval |
| **Windows, Linux** | paths in the command are checked first, and anything that can't be proven safe is refused |
| **Cloud-deployed agents** | every command runs in a locked container: the system read-only, only the agent's own folder writable, as a limited user. If the container can't be built, the command is refused, never run unwalled |

**Also:** environment variables that look like keys, tokens or passwords are removed before a command runs, so `echo $API_KEY` doesn't print a real key. That's a courtesy, not the safety boundary. The approval step is.

---

## Its tool

| tool | does |
|---|---|
| `execute_command` | run a command in this chat's terminal: optional folder, timeout, and `background` |

One tool, on purpose. Listing folders and file info (`ls`, `stat`) live here rather than as extra file tools, because each extra tool's description costs tokens on every turn.

---

## How agents are told to use it

- **Use it for structure and running things:** listing, moving, building, testing, installing.
- **Use the file tools for content:** reading and editing files go through [file](https://mycelen.com/manual/reference/toolkits/file), which handles formats, locks and secrets.
- **Long-running servers go to the background.**

---

## Approvals

- **Judged by what the command says.** `ls`, `cat`, `grep` and `git status` count as reads. `python`, `npm`, `pytest`, `mkdir`, `cp` and `mv` count as local changes. Anything unclear goes to the judge.
- **Always held in auto mode:**
  - `sudo`
  - deleting your home folder, a project root or `/`
  - printing a key-shaped variable
  - piping into `bash` or `python`
- **Always asks, whatever you've trusted:** `rm`, `rmdir`, `sudo`, `dd`, `chmod`, `chown`, `mkfs`, `shred`. A command with unbalanced quotes is treated as unsafe.
- **The approval card** shows the command in **Details**. There's no summary row for shell commands.

→ [Approvals & auto mode](https://mycelen.com/manual/how-it-works/approvals-and-auto-mode)

---

## Where you see it

- **Tool cards** in the chat, with the command and its output.
- **The terminal dock** (main agent): your own terminal in the chat's folder. It's a separate terminal from the agent's, in the same folder.
- **Background job messages** in the chat when a job finishes.

---

## What it costs

- **Free.** Commands run on your computer with no model call.
- **What it saves:** stored output almost never needs reading back, and a [reflex](https://mycelen.com/manual/guides/make-a-reflex) can drive the shell so intermediate output never enters the conversation.

---

## Limits

- 30-second default timeout, raised per command.
- 2 MB of output per stream per command.
- Up to 24 live terminals at once across Irene.
- A background job's report is lost if Irene restarts while it runs; the job is stopped and marked interrupted.
- Cloud-deployed agents run each command fresh (no memory between commands), inside a locked container.
- **This toolkit always runs on your Mac.** In a Coding chat on another computer, the Coding agent's own shell runs on that computer instead. → [Coding agent](https://mycelen.com/manual/reference/agents/coding)

---

## Related

- [File](https://mycelen.com/manual/reference/toolkits/file) · [Coding agent](https://mycelen.com/manual/reference/agents/coding) (its own shell, with checkpoints) · [Toolkits overview](https://mycelen.com/manual/reference/toolkits/overview)

[Ask Irene about this]
