Agent File Guardian
Provides a human-in-the-loop security layer for AI agents by intercepting file operations, explaining them with a local LLM, and enforcing a deterministic policy that requires user approval for risky actions.
README
Agent File Guardian

A small, honest gate between an AI agent and your files.
When you let an autonomous agent run on your machine, it inherits your machine's trust boundary. Agent File Guardian sits in front of file operations and runs each one through three steps before a single byte is touched:
- Triage — a local LLM (via Ollama) translates the raw request into one plain sentence and a rough risk label, so you can actually read what the agent is about to do.
- Policy — a deterministic rule file decides
allow/ask/deny. - Approval — anything marked
askpauses for a human yes/no, and everything is written to an append-only audit log.
agent ──▶ [ triage: explain + risk ] ──▶ [ policy: allow|ask|deny ] ──▶ [ human if 'ask' ] ──▶ file
(local LLM, (plain code — (you) + audit log
advisory only) the real boundary)
What this is — and what it is NOT
Please read this before trusting it with anything.
- This is a human-in-the-loop ergonomics layer, not a cryptographic sandbox. It makes "review every sensitive action" practical instead of exhausting.
- The local LLM never decides
allowordeny. That would make a prompt-injectable, non-deterministic component your security boundary — a bad idea. The LLM only explains. The decision lives inpolicy.yaml, in plain auditable code. If Ollama isn't running, the gate still works; you just lose the nice summaries. - It does not replace OS permissions, containers, or a real secrets vault. Run agents in a sandbox too. Treat this as defense-in-depth, not the whole defense.
If that framing is wrong or can be made stronger, that's exactly the kind of issue/PR this repo is hoping for.
Quick start (no agent needed)
pip install pyyaml pathspec
python demo.py # interactive: you approve the 'ask' cases
python demo.py --auto # scripted approvals, prints the whole trace
The demo builds a throwaway sandbox (a workspace/ folder, a personal/
folder, and a fake .env) and sends four agent requests through the gate so you
can watch allow / ask / deny happen and see the audit log fill in.
Real use: plug it into an agent over MCP
pip install "mcp[cli]"
python -m guardian.server # speaks MCP over stdio
Point an MCP-capable agent at it instead of giving it raw filesystem tools. Example Claude Desktop config:
{
"mcpServers": {
"file-guardian": {
"command": "python",
"args": ["-m", "guardian.server"],
"env": { "GUARDIAN_POLICY": "/absolute/path/to/policy.yaml" }
}
}
}
Approval prompts appear on your terminal (/dev/tty), since stdin/stdout carry
the MCP protocol. With no terminal attached, the server fails closed (denies
the ask case).
Writing policy
policy.yaml is the whole security boundary. Rules are checked top to bottom;
the first match wins, so put deny rules first. Patterns are gitignore-style
globs.
default_action: ask # allow | ask | deny — used when nothing matches
rules:
- name: "Block secrets and keys"
match_paths: ["**/.env", "**/*.key", "**/.ssh/**", "**/secrets/**"]
action: deny
- name: "Workspace reads are fine"
match_paths: ["workspace/**"]
operations: ["read", "list"]
action: allow
limits.max_write_bytes can only make a verdict stricter (an oversized allow
write is escalated to ask) — never looser.
Configuration (environment variables)
| Variable | Default | Meaning |
|---|---|---|
GUARDIAN_POLICY |
policy.yaml |
Path to the policy file |
GUARDIAN_AUDIT_LOG |
guardian-audit.log |
Append-only JSONL log |
GUARDIAN_OLLAMA_URL |
http://localhost:11434 |
Local LLM endpoint |
GUARDIAN_LLM_MODEL |
llama3.2 |
Ollama model for triage |
GUARDIAN_LLM_TIMEOUT |
8 |
Seconds before falling back to heuristic |
Ideas worth contributing
Honest about the gaps — these are open invitations, not finished claims:
- Path-traversal hardening: resolve
../symlinks and match policy on the real path before deciding. - Optional triage→escalation: let a
highLLM risk turn anallowinto anask(off by default, to keep the boundary deterministic). - Better approval channels: desktop notification or phone push instead of a terminal prompt.
- Per-session budgets: "allow up to N writes / this much total" within one agent run.
- More operations: move/copy/chmod, and non-text files.
License
MIT — see LICENSE. Built as a proof of concept to make the idea concrete. Fork it, break it, improve it.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。