Skip to content

DOCS

Guard policy

Guard reads ~/.balerx/policy.yaml on the machine. A missing file uses the built-in Balanced checklist (fail_open: true, timeout_ms: 250). Guard is a guardrail, not a sandbox. A present empty or unreadable file fails closed with ask. balerx doctor parses the file and exits 1 when it is empty or invalid. balerx setup prints a Balerx Gate banner, then writes that file. balerx setup --yes uses the balanced preset. --preset strict denies the shell, package, and MCP rows that balanced asks about, and writes fail_open: false with timeout_ms: 250. --preset minimal blocks secret files only. Existing files keep their fail_open and timeout_ms. --yes and --preset leave an existing file in place and exit with an error. Pass --replace to copy it to policy.yaml.bak and write a new one. balerx policy show prints the active policy. balerx policy edit opens the checklist again and keeps global.fail_open and global.timeout_ms. These commands stay offline. The checklist covers secret files, including cloud and CLI credential files, plus the shell, package, and MCP rows the hook engine can match.

Team can store a copy for the organization. balerx policy pull writes that copy into the same local file, or into a path you choose. See Teams.

The checklist does not offer a block on writes outside the project folder, a block on unknown or unpinned MCP servers, or a switch for the activity log. The hook engine cannot enforce those. Hook calls are still appended to the activity log.

Shape

version is required. global.fail_open defaults to true. global.timeout_ms defaults to 50. Those defaults also apply when global is omitted or is {}. The timeout wait starts when the evaluation thread is spawned after stdin is read, not at process start. The hook waits only that budget (minimum 25ms). A timeout asks. A stdin that never closes can still hang. A completed deny or ask is kept even after that budget. An evaluation that does not finish asks, regardless of fail_open. When the hook input is not JSON, fail_open true allows the tool and fail_open false denies it. That allow is written to the activity log and stderr. An empty, comment-only, or unreadable policy file always returns ask. Stdin larger than 1 MB also returns ask. The command normalize pass is one linear scan (capped at 256 KiB); if that scan cannot finish, Guard asks. Path globs run after canonicalization (~, $HOME, .., existing home/cwd symlinks, case). Path rules also see every path-like word from the whole command, including a cd/pushd destination, and evaluate that main-floor list in full. Tool-input JSON collects every file_path/filePath/path/target/filename/resource with no cap; a string prompt is skipped and a prompt object is walked. A * or ? word is not a protected path unless the glob can match one. MCP server names match without regard to case. npx <bin> is allowed when the effective cwd has node_modules/.bin/<bin> and that project directory or its node_modules/.bin is not world-writable; scoped names must match the full package; npx --package/--call and versioned specs ask; npm exec <bin> uses the same local-bin rule as npx. A new balanced file writes timeout_ms: 250. Setup and policy edit warn when an existing file keeps timeout_ms below 250.

deny_env_files matches .env. deny_env_dot_files matches names such as .env.local (**/.env.*). .environment-notes.md is not a secret env file. .env.example is still allowed.

Each rule has id, description, enabled, action, and conditions.

Actions are allow, deny, and ask.

Condition type is one of path_pattern, command_pattern, command_shape, server_allowlist, server_denylist, or resource_type. A command_pattern regex is applied exactly as written. Setup writes command_pattern so an older binary still loads the file; the current binary applies argv capabilities when that pattern is still the shipped default. A rule whose only conditions are unknown types is skipped with a warning. When known conditions match, the written action is kept. Shipped built-in patterns match on argv classification or the fallback regex, except over the exact byte ranges of proven data. Regexes shipped on main are also evaluated over the raw command.

Default rules

This is the policy a new organization starts from. deny_unapproved_mcp is present and disabled, so it does not block servers until you enable it.

version: "1.0.0"
global:
  fail_open: true
  timeout_ms: 50
rules:
  - id: deny_ssh_keys
    description: Deny reading files under .ssh
    enabled: true
    action: deny
    conditions:
      - type: path_pattern
        pattern: "**/.ssh/**"
  - id: deny_env_files
    description: Deny reading .env files
    enabled: true
    action: deny
    conditions:
      - type: path_pattern
        pattern: "**/.env"
  - id: deny_env_dot_files
    description: Deny reading .env.* files
    enabled: true
    action: deny
    conditions:
      - type: path_pattern
        pattern: "**/.env.*"
  - id: deny_pem_files
    description: Deny reading .pem certificate files
    enabled: true
    action: deny
    conditions:
      - type: path_pattern
        pattern: "**/*.pem"
  - id: deny_curl_pipe_sh
    description: Deny curl piped to a shell
    enabled: true
    action: deny
    conditions:
      - type: command_pattern
        pattern: "(?i)\\b(?:curl|wget)\\b[^|\\n]*\\|\\s*(?:sudo\\s+)?(?:sh|bash|zsh|dash|ksh|pwsh|powershell)\\b"
  - id: ask_force_push
    description: Ask before a force push
    enabled: true
    action: ask
    conditions:
      - type: command_pattern
        pattern: "(?i)(?:^|&&|\\|\\||[;&|])\\s*(?:sudo\\s+)?git\\b[^\\n]*\\bpush\\b[^\\n]*(?:--force(?:[\\s=]|$)|\\s-[a-zA-Z]*f[a-zA-Z]*\\b|\\s\\+)"
  - id: deny_unapproved_mcp
    description: Deny unapproved MCP servers
    enabled: false
    action: deny
    conditions:
      - type: server_denylist
        servers:
          - "*"

Examples you can add

Allow only named MCP servers:

  - id: approved_mcp
    description: Allow listed MCP servers
    enabled: true
    action: deny
    conditions:
      - type: server_allowlist
        servers:
          - filesystem
          - github

Match a resource class:

  - id: deny_shell_resource
    description: Deny shell resources
    enabled: true
    action: deny
    conditions:
      - type: resource_type
        types:
          - shell

Keep version and a rules list. The organization editor rejects a document without them, a document over 64,000 characters, and a document that contains !!.