# Which commands are safe to auto-approve for an AI agent on a server?

Commands that look like reads can write. See what find, sed, awk, tee and ssh really do, and what an allow list for an AI agent on a server should hold.

Source: https://valakes.com/learn/auto-approve-agent-commands/

Last updated: 2026-11-29

Only exact commands that read and cannot start another program. find, sed, awk, a redirection and ssh look like reads and are not, so a rule that allows them by name allows what they can do.

Commands checked on Ubuntu 24.04.5 LTS (the ubuntu:24.04@sha256:562111b88caa79c71391c0c4d3c2114a7d5c35915c20561fd893cb1e07929e6b container image), 29 November 2026.

Allow exact commands, with all their arguments, that only read: `df -h`, `uptime`, `systemctl status myapp.service`. Do not allow a program by name when it has an option or a built-in language that writes or starts another program. Anything that changes something waits for a person.

The account the agent logs in as is a separate subject, covered in [the article on AI agents on servers](https://valakes.com/learn/ai-agents-on-servers/). What I say about Claude Code and Codex comes from their documentation, linked at the end. The commands ran on the system named in the check line. `dev` stands for the account of the agent, and `app` is a second host it can reach over SSH.

## What the settings let you write

Claude Code has allow, ask and deny rules. Its documentation says they are checked in the order deny, then ask, then allow, and the first match decides. A rule with no `*` matches one exact command, and a `*` stands in for any text. This example allows two exact commands and denies a third:

```json
{
  "permissions": {
    "allow": ["Bash(df -h)", "Bash(systemctl status myapp.service)"],
    "deny": ["Bash(git push *)"]
  }
}
```

The rules live in the `settings.json` files, and `/permissions` lists them with the file each one comes from. The documentation says the rules are enforced by Claude Code, not by the model, so a line in a prompt or in `CLAUDE.md` does not change them. In `dontAsk` mode every call that would otherwise prompt is denied. What needs no approval in Manual mode, such as a read-only Bash command, still runs, and so do most calls that an allow rule covers. Nothing waits for an answer nobody gives. For a tool from an MCP server, the rule is `mcp__<server>__<tool>`, and an ask rule such as `mcp__<server>__*` makes every call of that server prompt, even when an allow rule also matches.

Codex has two settings. `approval_policy` is `on-request`, `never` or `granular`, where `granular` keeps chosen kinds of prompt, MCP prompts among them, and rejects the rest. `sandbox_mode` is `read-only`, `workspace-write` or `danger-full-access`. Its rules go in a `.rules` file, for example `~/.codex/rules/default.rules`:

```text
prefix_rule(
    pattern = ["systemctl", "status", "myapp.service"],
    decision = "allow",
)
```

The documentation says Codex compares the argument list of a command with the pattern, and the pattern must be an exact prefix. `allow` runs the command outside the sandbox without a prompt. When several rules match, the most restrictive one wins, in the order forbidden, prompt, allow. The page calls rules experimental.

## Commands that read and can also write

A rule that allows a program by name also allows its options, and some options write. The Claude Code documentation shows it for git: `Bash(git * main)` also matches `git -c core.fsmonitor=<script> diff main`, because the `*` takes any text. The five programs below ran in `/srv/app`, where `tmp` holds two cache files.

```console
$ cd /srv/app
$ find tmp -name '*.tmp'
tmp/b.tmp
tmp/a.tmp
$ find tmp -name '*.tmp' -delete
$ find tmp -type f | wc -l
0
```

The first `find` listed two files. The second one removed them. It is the same program with one more word. `-exec` runs any command on each match:

```console
$ find . -name app.conf -exec touch from-find \;
$ ls from-find
from-find
```

The Claude Code documentation covers this case: a prefix rule such as `Bash(find *)` does not approve `find` with `-exec`, `-delete`, `-fprint` and similar actions, and in Manual mode the call still prompts. That protection belongs to Claude Code. A list of command names in another tool or a script of your own does not have it.

`sed` looks like a filter. With `-n` and `p` it prints what it would change. With `-i` it changes the file:

```console
$ sed -n 's/debug/info/p' app.conf
log_level = info
$ cat app.conf
log_level = debug
$ sed -i 's/debug/info/' app.conf
$ cat app.conf
log_level = info
```

The Claude Code documentation lists `sed` with `mkdir`, `touch`, `rm`, `mv` and `cp` among the commands that `acceptEdits` mode approves as edits. `awk` is a programming language, and a program can start any command:

```console
$ awk 'BEGIN { system("echo ran as $(id -un) > from-awk") }'
$ cat from-awk
ran as dev
```

A redirection writes a file from a command that only reads, and so does `tee`:

```console
$ echo hi > from-redirect
$ cat app.conf | tee copy.conf
log_level = info
$ ls copy.conf from-redirect
copy.conf  from-redirect
```

Claude Code checks the target of a redirect and of `tee` against your file rules, as its documentation describes. A rule that matches the command text alone would not see the write.

The last one is `ssh`. A rule for `ssh app *` allows what comes after the host name, and the host runs it:

```console
$ ssh app hostname
app
$ ssh app 'touch marker && ls'
marker
```

The second command is one `ssh` command with one quoted argument. It created a file on `app`. By the documented meaning of `*`, a rule for `ssh app *` matches it. The documentation makes the same point about `devbox run *`: it matches whatever comes after `run`.

## What to put on the allow list for a server

Write the commands the agent should read with, each in the exact form, and nothing with a shell inside:

```text
df -h
uptime
free -m
systemctl status myapp.service
journalctl -u myapp.service -n 100 --no-pager
```

One rule per line, with no `*`. A variant, such as `journalctl` with another unit, is another rule or a prompt. Codex matches a pattern as a prefix, so there a rule also covers every longer command that starts with it. Keep each pattern long enough that every extension of it is harmless. Leave out `find`, `sed`, `awk`, `xargs`, `sh -c`, `bash -c`, `env`, `docker exec`, any interpreter, `ssh`, and every command with a redirect or a pipe into something that writes. The Claude Code documentation adds that a deny rule matches the form Claude usually writes. `rm *` does not stop `/bin/rm` or `bash -c 'rm ...'`, so a deny rule is not a security boundary, and the account and the sandbox are.

Keep an approval in front of writes, installs, restarts, deletes, `sudo` (see [what to do when Claude Code needs sudo](https://valakes.com/learn/claude-code-sudo/)) and tools from an MCP server that change something. Reads stay open to what the account can read, so a short list does not make a database password in a `.env` file safe.

## Mistakes people make

You allow `ssh app *` so that the agent can look around. It can do anything on `app` that the account there can do.

You allow `find *` or `sed *` as "read tools". Each is a write when the agent chooses an option.

You click "Yes, and don't ask again" on a compound command and never look at the rules it saved. The Claude Code documentation says it saves a rule for each subcommand that needed approval. Open `/permissions` and read them.

You turn on `bypassPermissions` or Codex's `--yolo` outside a throwaway environment. The Claude Code documentation says to use that mode only in isolated environments such as containers and VMs.

You expect the list to protect your files. An allowed `cat` reads every file the account may read, so a file is protected by its permissions and the list does nothing for it.

## In Valakes

The Read-only level of Valakes runs only commands from a fixed list (`ls`, `cat`, `head`, `tail`, `grep`, `find` without `-exec`, `ps`, `systemctl status` and a few more) with nothing that writes, redirects, expands or chains. The Help calls it an allow-list and not a sandbox: it judges the text of a command, so `cat ~/.ssh/id_ed25519` is a read to it. Approve writes asks for everything else, and Full asks for high-risk commands and for file transfers.

## In Valakes

The Read-only level of Valakes runs only a fixed list of read commands, with nothing that writes, redirects, expands or chains. The Help calls it an allow-list and not a sandbox, because it judges the text of a command and not what the program does. [Feature: AI agents](https://valakes.com/features/ai-agents/)

[Read the docs: Agents](https://docs.valakes.com/agents/)

## References

- [Claude Code documentation, permissions](https://code.claude.com/docs/en/permissions)
- [Claude Code documentation, permission modes](https://code.claude.com/docs/en/permission-modes)
- [Codex documentation, agent approvals and security](https://learn.chatgpt.com/docs/agent-approvals-security)
- [Codex documentation, rules](https://learn.chatgpt.com/docs/agent-configuration/rules)
- [OpenSSH manual pages, ssh(1)](https://www.openssh.org/manual.html)

## Related articles

- [How do I give an AI agent SSH access with the least damage?](https://valakes.com/learn/ai-agents-on-servers/): Give the agent its own account on the server, with no sudo, no password in the prompt and nothing secret in its reach. Let it read first, allow root for one exact command at most, make every change wait for a person, and keep a record of what ran.
- [What do I do when Claude Code needs sudo?](https://valakes.com/learn/claude-code-sudo/): Do not paste the password into the chat and do not write NOPASSWD ALL. Run the command with sudo -n so it fails at once, read what the account may run with sudo -l, and give the account a sudoers rule for that one command.
- [How do I let a user run one command with sudo?](https://valakes.com/learn/sudo-for-one-command/): Write a rule that names the command with its full path and exact arguments, put it in its own file under /etc/sudoers.d/, check it with visudo -cf, and install it with mode 440. Do not use wildcards in the arguments, and do not allow editors or any program that can start a shell.
