pyveil

Zero-dependency local PII and secret redaction for MCP servers, coding agents, and Python LLM apps. Air-gap local. No API key.

Drop-in MCP proxy, coding-agent hooks, and v0.4.0 highlights

Wrap stdio or Streamable HTTP/SSE MCP servers with pyveil proxy, guard Claude Code, Codex, and GitHub Copilot CLI tool calls with pyveil hook, or call Veil explicitly in Python. Zero core runtime dependencies, Python 3.8–3.14.

export PYVEIL_SECRET="$(python3 -c 'import secrets; print(secrets.token_hex(32))')"

# 1. One-command stdio MCP proxy (fail-closed -32001 on credentials)
python3 -m pyveil proxy --rulepack kr --audit-log pyveil-audit.jsonl \
  -- npx -y @modelcontextprotocol/server-filesystem .

# 2. Streamable HTTP / SSE local reverse proxy
python3 -m pyveil proxy --transport http \
  --listen 127.0.0.1:8787 --upstream http://127.0.0.1:9000/mcp
# 3. Print coding-agent hook configs (Claude Code / Copilot CLI / Codex)
python3 -m pyveil hook print-config --target claude-code
python3 -m pyveil hook print-config --target copilot-cli
python3 -m pyveil hook print-config --target codex

# Portable skill: skills/pyveil/SKILL.md
# Templates: hooks/claude-code/, hooks/codex/, hooks/copilot-cli/

From raw context to a redacted request

Install with python -m pip install pyveil, then run this complete example. Python 3.8+; no provider request.

import secrets

from pyveil import Channel, Veil

veil = Veil.high(secret=secrets.token_bytes(32), scope="support/session-42")
messages = [
    {"role": "user", "content": "Email alice@example.com about ticket 42."},
]
safe = veil.redact_data(messages, channel=Channel.PROMPT_INPUT)
print(safe.data[0]["content"])

Output shape (the HMAC suffix varies):

Email [EMAIL:...] about ticket 42.

Pass safe.data to your SDK. Roles and ticket 42 survive; the original input is unchanged.

Reuse this redactor within a session. For stable placeholders across restarts, load a private key from your environment or secret manager.

Python quickstart and key handling →

Only supported patterns are detected. Unknown names, addresses, images, and documents need a separate layer. See the detection board and limits.

One config. A real processed file.

python -m pip install pyveil==0.4.0
python -m pyveil init --example
python -m pyveil run

# Use --input /path/to/request.json
# instead of --example for your own file.
pyveil.json       executable settings
.pyveil.key       private local key

.pyveil-runs/<run-id>/
  redacted.json   actual processed data
  receipt.json    provenance, hashes, counts

The tutorial input is synthetic; processing uses the real installed redactor. No provider is called. Run twice for identical output bytes in separate directories. Install, run, reproduce, and handle failures.

Start with your integration

Installable provider helpers ship with pyveil. OpenAI Agents and LiteLLM wrappers are checkout recipes; each guide lists setup, keyless execution, and limits.

MCP proxy (stdio & HTTP/SSE)

Wrap any stdio or Streamable HTTP/SSE MCP server with one command and block tool credentials fail-closed.

Setup and options →

Claude Code, Codex & Copilot CLI

Attach PreToolUse/PostToolUse hooks and the portable SKILL.md without external runtime dependencies.

Hooks and templates →

OpenAI Agents SDK

Redact initial input before Runner.run. Run the checkout example without an API key.

Setup and boundary →

LiteLLM SDK and Proxy

Redact completion messages before dispatch. Compare the SDK wrapper and Proxy hook.

Setup and boundary →

OpenAI, verified without a key

Inspect the exact redacted Responses API input and run a real SDK contract test without network usage.

Read →

Claude, verified without a key

Redact Messages API content and verify its serialized request locally without consuming Claude credits.

Read →

Ollama, local and memory-aware

Run a tested 4B model on a 16GB Mac and inspect the exact redacted prompt before local inference.

Read →

Azure OpenAI, end to end

Load env or YAML, inspect the exact redacted prompt, then call the Azure v1 Responses API.

Read →

Known names and domain IDs

Redact values your application already knows plus narrow customer, account, or project identifier patterns.

Read →

Tool-call guard

Block auth headers, API keys, JWTs, private keys, and query secrets before model-controlled tools execute.

Read →

MCP resource wrapper

Redact files, records, logs, and API payloads before returning MCP resource content to an agent.

Read →

Memory write filter

Redact sensitive values before embedding and persisting long-lived agent memory.

Read →

Logging filter

Attach a standard logging filter so records are redacted before handlers and external sinks.

Read →

CLI preflight

Scan or redact files in local scripts and CI without adding runtime dependencies to your application.

Read →

Guides for the question you are solving

Demo

Synthetic local CLI run: PreToolUse .env deny, fail-closed MCP -32001 block, --rulepack kr masking, and raw-free JSONL audit (no live LLM API call).

pyveil blocking .env reads and masking MCP tool PII locally

Reproduced locally from the real installed CLI via scripts/render_demo_gif.py.