> For the complete documentation index, see [llms.txt](https://www.openclawbook.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.openclawbook.xyz/en/ch04-conversation-and-tools/4.2-bash-tools-in-practice.md). Agents can also search and read this documentation through its [MCP server](https://www.openclawbook.xyz/~gitbook/mcp).

# 4.2 Bash Tools in Practice

> **Generated by**: Claude Opus 5 (claude-opus-5\[1m]) **Token usage**: Input \~208,000 tokens, Output \~9,000 tokens (this section) **Source baseline**: `v2026.3.9` (`v2026.3.8-170-g665f67726`)

***

The `exec` tool is what makes OpenClaw "the AI that actually does things." This section covers using it — and, more importantly, understanding what it will and won't let happen.

## 4.2.1 File Management and Running Code

Ask in natural language; the agent picks the tools.

```
Find every .log file in ~/Downloads bigger than 100 MB and list them by size
```

```
This CSV has messy date formats. Normalize them to ISO 8601 and save a copy.
```

```
Run the test suite and tell me which tests fail and why
```

The agent has `read` / `write` / `edit` for files and `exec` for commands. It'll typically explore first (list a directory, read a file), then act.

### What makes this work well

**Give it the workspace.** OpenClaw runs with a workspace directory (`~/.openclaw/workspace` by default). Files there are its natural working area, and `AGENTS.md` in that directory is instructions it reads every session.

**Let it iterate.** Tasks like "make the tests pass" work because the agent can run, read the failure, edit, and run again. Prescribing each step removes that.

**Be specific about scope.** "Clean up this directory" is ambiguous and slightly alarming; "delete the `*.tmp` files in `./build`" is not.

## 4.2.2 System Management and Process Control

### Long-running commands

A command that doesn't finish quickly gets **backgrounded automatically** (§22.5.2): `exec` returns "still running" and hands management to the `process` tool.

So you can say:

```
Start the dev server, then check whether it's serving on port 3000
```

and the agent will background the server, poll its output, and report — rather than hanging until the server exits.

Process management commands available to it: list, poll, read log, write stdin, kill.

**Processes are isolated by session** — one conversation can't see or kill another's processes.

### Checking on things

```
Is anything using an unusual amount of CPU right now?
```

```
Show me the last 50 lines of the nginx error log and summarize what's wrong
```

## 4.2.3 The Security Model: What It Can and Can't Do

This is the part worth reading carefully.

### Three settings that control execution

| Setting    | Values                         | Default                   |
| ---------- | ------------------------------ | ------------------------- |
| `security` | `deny` / `allowlist` / `full`  | `allowlist` on the host   |
| `ask`      | `off` / `on-miss` / `always`   | `on-miss`                 |
| `host`     | `sandbox` / `gateway` / `node` | Depends on sandbox config |

**With the defaults**, a command not on the allowlist triggers an **approval request** — you get a message asking whether to permit it, and nothing runs until you answer.

### How approval works

```
The agent wants to run something not allowlisted
        ↓
You receive an approval request in chat
        ↓
Reply /approve <id>   (or reject)
        ↓
The command runs; the result comes back
```

The two-phase design (§22.5.2) exists because **the model's tool call is synchronous while your approval is asynchronous** — you might be looking at your phone ten minutes later.

You can approve permanently for a given command, which adds it to the allowlist. **That only happens if static analysis passes**, so you can't accidentally allowlist something dangerous by approving once.

### What the sandbox does and doesn't do

**The sandbox is off by default.** That's a deliberate choice consistent with OpenClaw's trust model (§44.4): it's a single-operator personal assistant, and commands run on the host.

Turning it on:

```json5
{
  agents: { defaults: { sandbox: { mode: "non-main" } } },
}
```

`non-main` is the useful setting: **your main session runs on the host** (it's your own instructions), while **subagents and group sessions run in containers** (paths that others might influence).

> **Understand what the sandbox protects.** It protects *you* from a runaway or manipulated agent. It is not a platform boundary protecting a service from its users — OpenClaw isn't built for that, and §44.4 says so plainly.

### Practical guidance

| Situation                                                 | Recommended setting                                                     |
| --------------------------------------------------------- | ----------------------------------------------------------------------- |
| Personal machine, you're the only user                    | Defaults are fine — `allowlist` + `on-miss` approval                    |
| Agent handling untrusted input (group chats, email hooks) | Turn on `sandbox: "non-main"`                                           |
| You want it to work unattended                            | Widen the allowlist deliberately rather than setting `security: "full"` |
| Shared or exposed machine                                 | Read Chapter 32 before proceeding                                       |

**Don't set `security: "full"` casually.** It removes approval entirely, meaning any successful prompt injection reaches your shell. If you're annoyed by approval prompts, the right fix is a broader allowlist of specific commands, not removing the gate.

***

## Section Summary

1. **Give the agent a goal and a workspace, and let it iterate** — running, reading failures, editing, and re-running is where the value is; prescribing each step removes it.
2. **Long-running commands are backgrounded automatically** and handed to the `process` tool, so a dev server doesn't hang the turn; **processes are isolated per session**.
3. **The defaults are `allowlist` + `on-miss` approval** — an unlisted command sends you an approval request and nothing runs until you answer.
4. **Approval is two-phase** because the model's call is synchronous while your approval is asynchronous; **permanent approval only applies when static analysis passes**, so a single approval can't allowlist something dangerous.
5. **The sandbox is off by default and protects you from a runaway agent** — it is not a platform boundary protecting a service from its users.
6. **`sandbox: "non-main"` is the useful setting**: main session on the host, subagents and group sessions in containers.
7. **Don't set `security: "full"` casually** — it removes the approval gate entirely, so any successful injection reaches your shell. Widen the allowlist instead.
