Skip to content
Isonapse
Install

Keep agents out of folders

One rule per folder keeps agents from reading or writing it, however the agent spells the path. A file merely named like the folder is outside it.

Works with: All four agents. On Codex and Hermes Agent these rules refuse a relative path, so the agent must use absolute paths. Supported hosts has the detail for each agent.

Steps

  1. 1. Start from your current policy

    isonapse hook policy export my-policy.lua

    This writes your active policy to my-policy.lua. Copy the rules you want from the example below into it. If the file already has a section of the same name, add the lines to that section.

  2. 2. Check that it loads

    isonapse hook policy check my-policy.lua

    This loads the file the way Isonapse does and names any file or folder pattern that can never match. It changes nothing.

  3. 3. Ask what each mode would do

    isonapse hook policy test --candidate my-policy.lua --read company-secrets/plan.txt

    Nothing runs, and no record is written. It prints one line per mode, with the reason; here Normal and Enforce refuse it.

  4. 4. Make it active

    isonapse hook policy activate my-policy.lua

    The terminal shows the exact change, and one approval with your login password makes it active. Use a plain terminal window that runs no agent, such as macOS Terminal or Ghostty.

  5. 5. Undo it

    isonapse hook policy revisions
    isonapse hook policy rollback <revision>

    The first lists earlier policies; the second restores one, with one approval and the password you log in to this computer with. Use a plain terminal window that runs no agent, such as macOS Terminal or Ghostty.

What it does not do

  • It checks the files a command visibly names; it is not operating-system confinement.
  • With a read rule, Normal and Enforce also refuse a command that runs code whose reads Isonapse cannot name, such as python or node. Profile records what it would refuse.
  • Pi's grep, find and ls search roots follow tool:Read folder rules, including relative paths and symlinks; grep and find path globs are checked too. Normal and Enforce refuse a covered or uncheckable read; Profile reports what it would refuse. Codex's write_stdin is not checked.
  • Unknown programs, changes after an action was approved and hard links that already exist outside the folder are not covered. Confining the agent's host is the durable boundary.
  • While a folder rule is in force, Git commands that rewrite the working tree, such as pulls and branch switches, are refused: run those yourself.

The policy

The whole example, 08-folder-rules.lua, from the examples Isonapse publishes.

-- 08-folder-rules.lua — keep agents out of folders.
--
-- A folder rule is a `blocked_file_patterns` entry that ends in `/` (or
-- `/**`). It covers the folder itself and every file below it, however the
-- agent spells the path: relative or absolute, through `.` or `..`, in
-- another letter case, or through a symbolic link that points into it. A
-- file merely named like the folder (`company-secrets.txt`,
-- `company-secrets-old/`) is outside it.
--
--   company-secrets/      — a folder of that name at any depth: at the
--                           repository root, deeper in it, or outside any
--                           repository (no working directory or `.git`
--                           entry changes that). A repository inside such a
--                           folder is covered as a whole: pick a
--                           distinctive name.
--   docs/internal/        — a folder `internal` directly in a folder `docs`,
--                           at any depth.
--   **/.ssh/              — the same as `.ssh/`: a folder of that name
--                           anywhere, the home folder's included.
--   /srv/payroll/         — an absolute folder.
--
-- One rule under `tool:Read` covers Read, NotebookRead, search roots and path
-- globs, native image paths, visible shell read operands and copy sources;
-- one under `tool:Write` covers every file write (Write, Edit, MultiEdit,
-- NotebookEdit, Codex apply_patch, and the shell writes Isonapse reads in a
-- command: redirections and the common commands that copy, move, link,
-- create, edit in place or remove files, Git's own file writes included).
-- Unusual shell forms can be misread; see the limits below. Moving a folder on the
-- way to a rule's folder (`mv docs x` under `docs/internal/`) or
-- hard-linking a covered file (`ln`, `cp -l`) is refused too, by read rules
-- as well; a symbolic link resolves on every use. Removing a folder that
-- holds a rule's folder (`rm -rf docs`, `git clean -fd`) is refused, and so,
-- while a folder rule is in force, is a write whose files cannot be listed
-- in advance: switching Git branches, `git pull`, `stash`, a Git restore of
-- a folder, `cpio -p`.
-- A folder needs its trailing `/`: `company-secrets` alone is a file name.
-- The rule denies even when an action rule permits the tool. Normal and
-- Enforce deny; Profile reports what it would deny. Claude Code and pi report
-- the folder a tool runs in; on Codex, Hermes and other hosts a relative path,
-- and a shell copy of a relative folder or wildcard, is denied by these rules
-- (write the absolute path).
--
-- An unknown read (opaque interpreters, sed programs, sourced scripts,
-- dynamic operands or search metadata beyond the bounded check) is refused
-- with a Read rule in Normal/Enforce; Profile records would-deny. This can
-- refuse ordinary interpreter commands too. Codex relative reads have no
-- known tool folder; use absolute paths. Its write_stdin bypasses PreToolUse.
-- Unknown programs, changes after authorization and hard links already
-- outside the folder remain uncovered. Host confinement is the durable
-- route. On the write side, unmodelled programs (an archive extractor,
-- find -delete) remain outside the projected file writes.
return {
  policy_version = "folder-rules-v1",

  blocked_file_patterns = {
    ["tool:Read"] = {
      "company-secrets/",
      "docs/internal/",
      "**/.ssh/",
      "/srv/payroll/",
    },
    ["tool:Write"] = {
      "company-secrets/",
      "docs/internal/",
      "**/.ssh/",
      "/srv/payroll/",
      -- The hardened self-protection lines every template carries.
      "**/isonapse*",
      "**/managed-settings*",
    },
  },
}

Stuck? Help finds the message you see.