Skip to content
Back to skills

Shell Execution Sandbox

ASecurity

Enable and configure the sandboxed shell execution tool with command allowlists, Docker isolation, and audit logging for agents that run terminal commands.

  • 33 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added October 11, 2026
ai-agentstypescriptpythonrustgoshellreactnodedockergitapi

Works with

  • terminal
  • api

Security analysis

A100/100

Scanned December 5, 2026

npx -y skills add tylerjrbuell/reactive-agents-ts --skill shell-execution-sandbox --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Shell Execution Sandbox?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Shell Execution Sandbox
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/tylerjrbuell-shell-execution-sandbox/badge)](https://www.skillsdirectory.com/skills/tylerjrbuell-shell-execution-sandbox)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: shell-execution-sandbox
description: Enable and configure the sandboxed shell execution tool with command allowlists, Docker isolation, and audit logging for agents that run terminal commands.
compatibility: Reactive Agents TypeScript projects using @reactive-agents/*
metadata:
  author: reactive-agents
  version: "2.0"
  tier: "capability"
---

# Shell Execution Sandbox

> **Disclaimer — your machine, your risk.** `shell-execute` runs real processes on the host (or in an optional Docker sandbox you configure). Allowlists and blocklists reduce accidents but are not a guarantee. Only enable for trusted codebases and accounts; review allowed command names and working-directory rules before production use. Cortex exposes this as an **explicit opt-in** in the Lab builder with the same warning.

## Agent objective

Produce a builder with shell execution enabled, the correct allowlist for the task, and appropriate safety config — without exposing destructive commands.

## When to load this skill

- Agent needs to run terminal commands (git, file operations, build tools)
- Agent generates and executes code (Node, Bun, Python)
- Task requires reading directory structure, running tests, or processing files
- CI/CD or automation agent workflows

## Implementation baseline

```ts
const agent = await ReactiveAgents.create()
  .withProvider("anthropic")
  .withReasoning({ defaultStrategy: "plan-execute-reflect", maxIterations: 15 })
  .withTools({
    allowedTools: ["shell-execute", "file-read", "checkpoint"],
    terminal: true, // registers the shell-execute handler
  })
  .withSystemPrompt(`
    You have access to a shell. Use it to explore the codebase and run commands.
    Always checkpoint important findings before continuing.
  `)
  .build();
```

## Default allowlist

The `shell-execute` tool blocks any command not on the allowlist. Default allowed commands:

```
git, ls, cat, grep, find, echo, printf
mkdir, cp, mv, touch
wc, head, tail, sort, uniq, cut, tr, tee, diff, sed, awk, jq
pwd, date, which, basename, dirname, test, true, false
seq, gzip, gunzip, zip, unzip
```

**Explicitly excluded:** `rm`, `chmod`, `chown` — too destructive for agent sandboxes.

## Key patterns

### Opt-in commands for build tasks

Build tools (Node, Bun, npm, Python, curl) are available but not on by default:

```ts
// Available opt-in commands: node, bun, npm, npx, python, python3, curl, env, xargs, tar
// Add via ShellExecuteConfig.additionalCommands when registering the tool:
import { shellExecuteTool, shellExecuteHandler } from "@reactive-agents/tools";

const shellTool = {
  definition: shellExecuteTool,
  handler: shellExecuteHandler({
    additionalCommands: ["bun", "node", "npm"],
    timeoutMs: 60_000,        // default 30s — increase for build commands
    maxOutputChars: 8_000,    // default 4000
    cwd: "/tmp/build",        // must be under /tmp unless allowUnsafeCwd: true
  }),
};

const agent = await ReactiveAgents.create()
  .withTools({ tools: [shellTool], allowedTools: ["shell-execute"] })
  .build();
```

### Working directory: use `workspace`, not a custom handler

To run the shell in a project directory, set the agent's workspace. File tools
and `shell-execute` then share one root:

```ts
const agent = await ReactiveAgents.create()
  .withTools({ terminal: { additionalCommands: ["bun"] }, builtins: ["file-write"], workspace: "/home/me/project" })
  .build();

await agent.run("Run the tests");                                  // shell cwd = /home/me/project
await agent.run("Run the tests", { workspace: "/home/me/other" }); // this run only
```

- No `terminal.cwd`: the shell runs in the workspace.
- `terminal.cwd` relative: resolved inside the workspace. Outside it: refused,
  unless `terminal.allowUnsafeCwd: true`.
- No workspace: unchanged (fresh `/tmp/rax-sandbox-*` dir; `cwd` must be under `/tmp`).
- A custom `shell-execute` handler passed in `tools` is not rebound; only the
  built-in `terminal` tool follows the workspace.

### Paths outside the workspace: `additionalRoots`

Paths in a shell command (and in file tools) must stay inside the workspace,
which is always read-write, or a root you grant. Roots are read-only unless
`access: "read-write"`:

```ts
.withTools({
  terminal: true,
  workspace: "/home/me/project",
  additionalRoots: [{ path: "~/docs" }, { path: "/data/out", access: "read-write" }],
})
```

- In a read-only root the shell runs only `cat`, `ls`, `head`, `tail`, `wc`,
  `grep`, `diff`, `stat`, `file`, `du`, with no output redirect.
- When roots nest, the deepest one decides. A write needs read-write on both
  the written path and where its symlinks lead.
- `~` and `~/x` expand to the user's home; `~user` is refused.
- Refusals list the allowed roots and name `additionalRoots`. Sub-agents
  inherit the roots; each run records them on
  `run-started.config.builder.tools.additionalRoots`.

### Docker-isolated code execution

When `dockerEscalation` is enabled, inline code (Node `--eval`, Bun `-e`, Python `-c`) automatically routes through a Docker sandbox:

```ts
shellExecuteHandler({
  additionalCommands: ["node", "python3"],
  dockerEscalation: {
    enabled: true,
    // Inline code execution is fully isolated in a fresh container
  },
})
```

### Read-only shell (safest config)

```ts
shellExecuteHandler({
  allowedCommands: ["ls", "cat", "grep", "find", "head", "tail", "wc"],
  // Only listing and reading — no writes, no execution
})
```

### Audit logging

```ts
shellExecuteHandler({
  onAudit: (entry: ShellAuditEntry) => {
    logger.info("shell-execute", {
      command: entry.command,
      allowed: entry.allowed,       // entry: { command, allowed, reason?, exitCode?, timestamp }
      exitCode: entry.exitCode,
    });
  },
})
```

## Shell tool properties

The `shell-execute` built-in tool has these characteristics:

| Property | Value |
|----------|-------|
| `riskLevel` | `"high"` |
| `requiresApproval` | `true` |
| `category` | `"system"` |
| `timeoutMs` (default) | 30,000ms |
| `maxOutputChars` (default) | 4,000 chars |
| `MAX_COMMAND_LENGTH` | 4,096 chars |

### Allowed-command metadata and PATH availability

The tool definition carries `commandPolicy` (`allowedCommands`, `notEnabledCommands`, `sandbox`, `workingDirectory`), derived from the same allowlist the handler enforces. `shellCommandAvailability(def.commandPolicy)` from `@reactive-agents/tools` reports which allowed commands exist on PATH (cached, no spawn, host shell only). A planner needs no step like `gh --version`. A call with no `command` returns `Missing required parameter "command". Valid call: shell-execute({"command":"git log --oneline -5"})`.

## Builder API reference

| Method | Key params | Notes |
|--------|-----------|-------|
| `.withTools({ tools, allowedTools })` | include `"shell-execute"` | Register custom handler for config |
| `.withTools()` | no args | Does NOT enable shell-execute; it is available only with `terminal: true` (approval required) |
| `.withTools({ terminal: true, workspace })` | absolute or relative dir (must exist) | Shell cwd and file-tool root = workspace; `run(task, { workspace })` overrides per run |
| `.withTools({ additionalRoots })` | `{ path, access?: "read" \| "read-write" }[]` | Extra directories for file tools and the shell; `access` defaults to `"read"`; none by default |

## Pitfalls

- A command the policy would refuse (not on the allowlist, blocked pattern, expansion) is refused without an approval prompt: the tool's `preflight` runs the same checks before approval and the model sees the identical refusal. Checks that depend on the working directory (path escapes, `cd`) still run at execution
- `shell-execute` has `requiresApproval: true` by default — in automated pipelines, register a custom handler with `requiresApproval: false` if human approval flow is not wired
- Commands are allowlisted by **executable name only** (first word) — `git` is allowed regardless of sub-command args; `curl` is opt-in
- `MAX_COMMAND_LENGTH` is 4,096 — very long piped commands will be rejected
- Background `&` (`sleep 1 &`, `a & b`) is refused because it escapes the timeout. Redirects that contain `&` are allowed: `2>&1`, `>&2`, `&>file`, `&>>file` and `|&`. Every redirect target is path-checked like any other argument, so `2>/etc/x` and `&>../x` are refused
- A redirect whose target is exactly `/dev/null` is allowed: `2>/dev/null`, `>/dev/null`, `&>/dev/null`, `>>/dev/null`, `</dev/null`, quoted or not. Every other `/dev/` target is refused (`>/dev/sda`, `>/dev/tcp/host/1`, `>/dev/null2`, `>/dev/./sda`), and a redirect glued after the null one is still checked (`2>/dev/null>/etc/x` is refused). The read-only git/gh shell refuses every output redirect except a descriptor dup and a redirect to exactly `/dev/null` (`git log 2>/dev/null` runs)
- `$VAR`, `${...}`, `$(...)`, backticks and `<(...)` are refused; single quotes keep `$` literal (`awk '{print $1}'`)
- Docker daemon must be running for `dockerEscalation` — check before enabling in CI
- `rm`, `chmod`, `chown` are hard-excluded and cannot be added via `additionalCommands`
- `maxOutputChars: 4000` truncates long output — increase for commands that produce large output (e.g., `git log`, `find` on large trees)

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.