greg is designed from the ground up with a fail-closed security architecture. Because greg operates as an autonomous print agent in non-interactive terminals, scripts, and CI environments, it cannot pause execution to ask for human confirmation on every tool call.
Instead, greg relies on deterministic, pre-execution authorization policies. If an operation is not explicitly authorized by your active permission mode or allowed tool rules, it is immediately denied.
For the underlying architectural mechanics of how the policy guardrail integrates into the Hernex engine loop, see How Greg Works. For lifecycle event interceptors, see Lifecycle Hooks.
- The Fail-Closed Security Model: Why non-interactive autonomous agents must fail closed.
- Declarative Permission Modes: Comparing
default,acceptEdits,plan, andbypassPermissions. - Wildcard Scoped Tool Rules: Syntax, target normalization, and compilation for
Tool(pattern). - Denial Precedence: Why
--disallowed-toolsstrictly overrules allow rules. - TaskManager & Shell Coupling: Why background processes require explicit Bash authorization.
- Configuring Permissions: Applying rules via CLI flags and persistent
settings.json. - Security Best Practices: Hardening configurations for local machines, CI runners, and shared environments.
- Next Steps: Guided links to deeper guides.
The Fail-Closed Security Model
In interactive terminal chat UIs, when an agent wants to run a shell command or edit a file, it presents a prompt:Allow Bash("rm -rf tmp")? [y/N]. While this works for casual interactive use, it breaks down in automated pipelines, cron jobs, and terminal pipes.
greg eliminates interactive prompts in favor of deterministic pre-execution evaluation:
- Deterministic Evaluation: Every tool call is evaluated against compiled wildcard regular expressions before touching disk or spawning child processes.
- Contextual Rejection Feedback: When an action is denied,
greginjects a structured denial reason into the model’s message history. The model understands why it was blocked and can adjust its strategy without crashing the run. - Audit Trail: Every denial is recorded in run metrics and logged to
stderr.
Declarative Permission Modes
greg provides four built-in permission modes specified via --permission-mode <mode>:
1. default Mode (Read-Only)
The default mode when no flag is passed. The model can inspect your codebase using Read, Glob, Grep, Lsp, WebFetch, and WebSearch, but cannot write files or execute shell commands:
greg rejects the call:
2. acceptEdits Mode (File Mutations)
Authorizes greg to create, write, and edit files while continuing to block arbitrary shell commands:
acceptEdits is automatically snapshotted in content-addressed storage before writing, allowing instant undo with greg checkpoints restore 1.
3. plan Mode (Reconnaissance)
In plan mode, Write, Edit, and Bash are completely filtered out of the model’s available tools (planModeToolNames). The model cannot even attempt mutations; it can only formulate implementation plans:
4. bypassPermissions Mode (Unrestricted)
Disables all permission checks. File edits and shell commands run without restrictions:
--dangerously-skip-permissions as a standalone flag in any command:
Use
bypassPermissions and --dangerously-skip-permissions exclusively in sandboxed environments, ephemeral Docker containers, or trusted CI/CD pipelines.Wildcard Scoped Tool Rules
To grant granular permissions without opening unrestricted shell access, use Scoped Tool Rules with--allowed-tools:
Rule Syntax: Tool(pattern)
Tool rules use PascalCase tool names followed by parentheses containing a matching target:
How Target Matching Operates
- Path Normalization: File paths passed to
Write,Edit, orReadare resolved againstprocess.cwd(), normalized to relative forward-slash paths (src/utils/math.ts), preventing directory traversal (../../etc/passwd) escapes. - Wildcard Glob Expansion (
*): The*token matches zero or more non-separator characters, or across subdirectories depending on context. - Escaping: To match a literal asterisk or backslash, escape it with
\*or\\. - Anchored Boundaries: Patterns are compiled into full-string anchored regular expressions (
^...$), ensuring thatBash(git status)only matchesgit status, notgit status && rm -rf /.
Denial Precedence
Security rules ingreg strictly prioritize safety: Disallow rules always win over allow rules.
When --disallowed-tools is specified, any tool invocation matching a disallowed rule is denied immediately, even if it matches an --allowed-tools rule or the active --permission-mode:
rm -rf dist, execution is rejected:
TaskManager & Shell Coupling
greg includes a background task manager powered by Hernex’s TaskManagerTool. Background tasks spawn asynchronous sub-processes (such as starting a local development server or running a long test suite).
To maintain strict security boundaries, TaskManager is directly coupled to Bash authorization:
TaskManagercannot be authorized independently.- In
defaultoracceptEditsmode, background tasks are permitted only ifBashis explicitly allowed (e.g.--allowed-tools "Bash(*)"). - If
Bashis denied, any attempt to spawn background tasks fails closed.
Configuring Permissions
You can apply permission rules dynamically per command or persist them globally for your project:1. Per-Command CLI Flags
2. Persistent Project Settings (.greg/settings.json)
To avoid typing permission flags on every command, persist rules in your project configuration:
Security Best Practices
1. Principle of Least Privilege
Always start withdefault (read-only) or acceptEdits mode. Only authorize the specific shell commands needed for verification (e.g. Bash(npm test) or Bash(cargo check)).
2. Guard Sensitive Branches in Git
Never allow unrestrainedgit push in shared environments. Disallow pushes to production branches:
3. Combine Permissions with Lifecycle Hooks
For multi-layer security, combine--disallowed-tools with a PreToolUse lifecycle hook that inspects argument payloads before execution. See Lifecycle Hooks.
4. Rely on Checkpoints for Recovery
If an authorized file edit introduces unwanted changes, usegreg checkpoints restore 1 to instantly revert the workspace back to its pre-mutation state.
Next Steps
Now that you understand permission evaluation and security rules:- Common Workflows: Explore real-world developer recipes with scoped permissions.
- Lifecycle Hooks: Learn how to build custom pre-execution shell guardrails.
- How Greg Works: Inspect the complete agent execution cycle and engine architecture.