Skip to main content
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.
This page covers:

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:
  1. Deterministic Evaluation: Every tool call is evaluated against compiled wildcard regular expressions before touching disk or spawning child processes.
  2. Contextual Rejection Feedback: When an action is denied, greg injects 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.
  3. 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:
If the model attempts to edit a file, greg rejects the call:

2. acceptEdits Mode (File Mutations)

Authorizes greg to create, write, and edit files while continuing to block arbitrary shell commands:
Every file edit made under 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:
You can also pass --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

  1. Path Normalization: File paths passed to Write, Edit, or Read are resolved against process.cwd(), normalized to relative forward-slash paths (src/utils/math.ts), preventing directory traversal (../../etc/passwd) escapes.
  2. Wildcard Glob Expansion (*): The * token matches zero or more non-separator characters, or across subdirectories depending on context.
  3. Escaping: To match a literal asterisk or backslash, escape it with \* or \\.
  4. Anchored Boundaries: Patterns are compiled into full-string anchored regular expressions (^...$), ensuring that Bash(git status) only matches git status, not git status && rm -rf /.

Denial Precedence

Security rules in greg 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:
If the agent attempts to run 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:
  • TaskManager cannot be authorized independently.
  • In default or acceptEdits mode, background tasks are permitted only if Bash is explicitly allowed (e.g. --allowed-tools "Bash(*)").
  • If Bash is 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:
View active permissions:

Security Best Practices

1. Principle of Least Privilege

Always start with default (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 unrestrained git 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, use greg 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.