secretsh
Inject secrets from a .env file into subprocess arguments for AI agents.
Honest summary: secretsh keeps secrets out of LLM context and shell history, and redacts them from stdout/stderr. It does not protect the
.envfile, hide secrets from the child process, or redact files the child writes directly. See docs/threat-model.md.
Agent writes: curl -H 'X-Api-Key: {{NINJA_API_KEY}}' 'https://api.example.com'
Child runs: curl -H 'X-Api-Key: sk-realkey123' 'https://api.example.com'
Agent sees: [{"result": "..."}] ← [REDACTED_NINJA_API_KEY] if leaked in output
Install
# CLI (Rust)
&&
# or: cargo install secretsh
# Python (wraps the CLI binary — install CLI first)
# or: uv add secretsh
Pre-built binaries: GitHub Releases.
Quick Start
&&
=
# [{"quote": "...", "author": "..."}]
Agent Tool (LangChain)
"""Run a command with secrets from .env. Use {{KEY_NAME}} placeholders.
Single-quote arguments containing spaces, pipes, $ or &."""
=
return or
return f # lists available key names
return f
return f
Flags
| Flag | Default | Purpose |
|---|---|---|
--env |
required | Path to the .env file |
--no-shell |
off | Block sh/bash/zsh/etc. Recommended for AI agents. |
--timeout |
300s | Kill child after N seconds |
--max-output |
50 MiB | Kill child if stdout exceeds this |
--max-stderr |
1 MiB | Kill child if stderr exceeds this |
--quiet |
off | Suppress audit JSON on stderr |
--verbose |
off | Show tokenization debug output |
Exit Codes
| Code | Meaning |
|---|---|
| 0 | Success |
| 1–125 | Child exit code (passthrough) |
| 124 | Timeout or output limit exceeded |
| 125 | secretsh error (tokenization, placeholder, shell blocked) |
| 126 / 127 | Not executable / not found |
| 128+N | Killed by signal N |
Documentation
| Doc | Content |
|---|---|
| docs/cli.md | Flags, quoting guide, exit codes |
| docs/python-api.md | secretsh.run() API, quoting guide, exceptions |
| docs/tokenizer.md | Allowed/rejected chars, placeholder syntax |
| docs/threat-model.md | Security model, oracle attacks, limitations |
| docs/architecture.md | Execution pipeline, module map |
| docs/integrations/ | LangChain, PydanticAI, OpenClaw |
| examples/ | LangChain demo, runnable examples |
Development
&& &&
&& PYTHONPATH=.
License
MIT · Contributing · Security