Skip to main content

Exec Tool — Developer Reference

Type definitions, policy precedence, and implementation details for the exec tool and its approval system.

Source files

ExecToolConfig

approvalRunningNoticeMs is only accepted on agent-level exec config (AgentToolExecSchema), not the global ToolExecSchema.

AgentToolsConfig

FsToolsConfig

ExecApprovalsFile schema

Defaults at runtime:

ApprovalsConfig (approval forwarding)

Global vs agent-level precedence

Effective exec policy is the stricter of config (tools.exec.* / agents.list[].tools.exec.*) and exec-approvals.json. Omitted approvals fields fall back to the config value. Global (tools.exec) sets the floor. Agent-level (agents.list[].tools.exec) overrides. exec-approvals.json overrides per-agent at runtime (hot-reloaded, not requiring gateway restart). Config schema uses two separate shapes:
  • ToolExecSchema — global, no approvalRunningNoticeMs
  • AgentToolExecSchema — extends base with approvalRunningNoticeMs

Tool policy filtering order

Tool availability is determined in this order (each level can only further restrict):
  1. Tool profile (tools.profile or agents.list[].tools.profile)
  2. Provider tool profile (tools.byProvider[provider].profile)
  3. Global tool policy (tools.allow / tools.deny)
  4. Provider tool policy (tools.byProvider[provider].allow/deny)
  5. Agent-specific tool policy (agents.list[].tools.allow/deny)
  6. Agent provider policy (agents.list[].tools.byProvider[provider].allow/deny)
  7. Sandbox tool policy (tools.sandbox.tools or agents.list[].tools.sandbox.tools)
  8. Subagent tool policy (tools.subagents.tools)
deny always wins. A non-empty allow makes everything not listed implicitly blocked. Tool policy is the hard stop — /exec cannot override a denied exec tool. If agents.list[].tools.sandbox.tools is set, it replaces tools.sandbox.tools for that agent.

Tool groups

Tool policies support group:* shorthands:

Safe bin implementation

SafeBinProfileFixture defines the argv policy for a safe bin:
Validation is deterministic from argv shape only (no filesystem existence checks). Safe bins force argv tokens to be treated as literal text (no globbing, no $VAR expansion). Long options are fail-closed: unknown flags and ambiguous abbreviations are rejected. Default denied flags per bin:
  • grep: --dereference-recursive, --directories, --exclude-from, --file, --recursive, -R, -d, -f, -r
  • jq: --argfile, --from-file, --library-path, --rawfile, --slurpfile, -L, -f
  • sort: --compress-program, --files0-from, --output, --random-source, --temporary-directory, -T, -o
  • wc: --files0-from
Shell chaining (&&, ||, ;) is allowed only when every top-level segment satisfies the allowlist (including safe bins). Redirections are unsupported in allowlist mode. Command substitution ($() / backticks) is rejected during allowlist parsing. Safe bins must resolve from trusted directories (defaults: /bin, /usr/bin). PATH entries are never auto-trusted. Add package-manager paths via tools.exec.safeBinTrustedDirs. safeBinProfiles — per-agent profile keys override global keys.

apply_patch subtool

apply_patch is a subtool of exec for structured multi-file edits (OpenAI models only):
Tool policy: allow: ["exec"] implicitly allows apply_patch. workspaceOnly defaults to true (workspace-contained). Config lives under tools.exec.applyPatch.

Shell environment notes

  • OPENCLAW_SHELL=exec is set in the spawned command environment (including PTY and sandbox) so shell/profile rules can detect exec-tool context.
  • On non-Windows: uses SHELL; if SHELL is fish, prefers bash/sh from PATH, then falls back to fish.
  • On Windows: prefers PowerShell 7 (pwsh), falls back to PowerShell 5.1.
  • Host execution (gateway/node) rejects env.PATH and loader overrides (LD_*/DYLD_*).
  • Script preflight checks inspect only files inside the effective workdir boundary; paths resolving outside workdir skip preflight.

elevatedDefault

Sets the default elevated level when no /elevated directive is present for a session. "full" skips exec approvals entirely. Related: Exec Tool (user) · Exec Tool (admin) · Sandboxing (developer)