OnGarde โ Runtime content security layer for self-hosted AI agent platforms
Project description
OnGarde ๐คบ
Runtime Security for Self-Hosted AI Agents
OnGarde is a transparent security proxy for self-hosted AI agent platforms. It intercepts every LLM request and response, scans for threats in under 50ms, and blocks credential leaks, dangerous commands, PII, and prompt injection โ without changing a line of your agent code.
What It Does
OnGarde sits between your AI agent and the LLM provider. Zero code changes required โ just point your baseUrl at OnGarde.
Blocks by default:
- ๐ Credential & API key leaks
- ๐ฃ Dangerous shell commands (
rm -rf,sudo, fork bombs) - ๐ต๏ธ Prompt injection attempts
- ๐ชช PII (SSNs, credit cards, personal data)
- ๐ Sensitive file access (
.env,.ssh/*,/etc/passwd)
Fail-safe: errors and timeouts default to BLOCK โ security over availability.
Quick Start
OpenClaw (One Command)
npx @ongarde/openclaw init
Automatically configures OnGarde as your OpenClaw proxy. No YAML editing required.
Manual Setup
Prerequisites: Python 3.12+
# Clone and install
git clone https://github.com/AntimatterEnterprises/ongarde.git
cd ongarde
pip install -r requirements.txt
python -m spacy download en_core_web_sm
# Configure
cp .ongarde/config.yaml.example .ongarde/config.yaml
# Edit .ongarde/config.yaml โ set upstream: <your LLM URL>
# Run
python -m app.run
Then create your first API key (unauthenticated on first call):
curl -X POST http://127.0.0.1:4242/dashboard/api/keys \
-H "Content-Type: application/json" \
-d '{"name": "my-agent"}'
# Returns: { "key": "ong-xxxxxxxxxxxxxxxxxxxx", ... }
OnGarde works with any OpenAI-compatible API โ the standard protocol used by OpenAI, Anthropic, Mistral, Groq, Together AI, OpenRouter, Ollama, LM Studio, and most agent platforms:
# Point your agent at OnGarde โ use your OnGarde API key, not a provider key
from openai import OpenAI
client = OpenAI(
api_key="ong-xxxxxxxxxxxxxxxxxxxx", # your OnGarde key
base_url="http://localhost:4242/v1",
)
# Or set via environment variable โ works for all frameworks and SDKs
export OPENAI_BASE_URL="http://localhost:4242/v1"
export OPENAI_API_KEY="ong-xxxxxxxxxxxxxxxxxxxx"
Note: The
api_keyfield here is your OnGarde API key (ong-xxxx), not your upstream provider key. OnGarde forwards requests to your configured upstream with its own auth.
Authentication is on by default.
ONGARDE_AUTH_REQUIRED=trueโ every request requires an API key. Thenpx @ongarde/openclaw initwizard creates your first key automatically. For manual setup, see the API key instructions in QUICKSTART.md.
See QUICKSTART.md for full setup details.
Performance
Benchmarked on a 2 vCPU / 4 GB DigitalOcean Droplet (recommended production hardware):
| Operation | Input size | p50 | p99 |
|---|---|---|---|
| Regex scan (credentials, shell commands) | up to 8 KB | < 0.5ms | < 1ms |
| Full scan (regex + NLP/PII detection) | 100 chars (~75 tokens) | 8ms | 9ms |
| Full scan (regex + NLP/PII detection) | 500 chars (~375 tokens) | 16ms | 20ms |
| Full scan (regex + NLP/PII detection) | 1,000 chars (~750 tokens) | 28ms | 33ms |
| Streaming window scan | 512-char window | < 0.3ms | < 0.2ms |
Target: < 50ms total overhead โ met across all typical LLM prompt sizes.
OnGarde auto-calibrates at startup: it benchmarks scan latency on your hardware and adjusts the NLP sync threshold accordingly. On slower or single-core machines it automatically reduces the Presidio scan cap to stay within budget โ no manual tuning required.
Project Structure
ongarde/
โโโ app/ # Core proxy application (FastAPI)
โ โโโ main.py # Entry point
โ โโโ proxy/ # Request interception & streaming
โ โโโ scanner/ # Threat detection engine
โ โโโ rules/ # Security rule definitions
โ โโโ audit/ # Audit trail (SQLite + Supabase)
โ โโโ auth/ # API key management
โ โโโ allowlist/ # False-positive recovery
โ โโโ dashboard/ # Web dashboard (:4242/dashboard)
โ โโโ utils/ # Logging, helpers
โโโ packages/
โ โโโ openclaw/ # npm CLI (@ongarde/openclaw)
โโโ tests/ # 1,222 tests (unit, integration, security)
โโโ benchmarks/ # Performance benchmarks & results
โโโ demo/ # Interactive demo scripts
โโโ tools/ # Diagnostic & helper scripts
โโโ docs/ # Technical documentation
โโโ .ongarde/ # Config templates
Dashboard
Once running, open http://localhost:4242/dashboard to see:
- Live scan counts and block rate
- Recent blocked events with full context
- Scanner health and quota status
- API key management
Localhost only. The dashboard is accessible exclusively from the local machine. Requests from remote IPs are rejected with HTTP 403, enforced at the code level.
Security Model
Streaming vs Non-Streaming
| Mode | Guarantee |
|---|---|
| Non-streaming | Absolute โ response never forwarded before scan passes |
| Streaming (SSE) | Best-effort โ per 512-char window with 128-char overlap |
Streaming limitation: up to one 512-char window (~128 tokens) may reach the agent before termination. Use
stream: falsefor absolute guarantees on sensitive workloads.
Full details: docs/STREAMING_SECURITY_MODEL.md
Testing
# Full suite
pytest tests/ -v
# Security tests only
pytest tests/security/ -v
# With coverage
pytest tests/ --cov=app --cov-report=term-missing
1,222 tests. 0 failures.
Documentation
- QUICKSTART.md โ Setup and configuration
- CHANGELOG.md โ Release history
- docs/deployment.md โ Production deployment guide
Contributing
Issues and PRs welcome. Please open an issue before starting significant work so we can discuss direction.
License
MIT โ see LICENSE.
Links
- Website: ongarde.io
- Issues / Contact: github.com/AntimatterEnterprises/ongarde/issues
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ongarde-1.0.0.tar.gz.
File metadata
- Download URL: ongarde-1.0.0.tar.gz
- Upload date:
- Size: 106.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
69cd2ccaf07b42798c948006d40ad747e9207ecb0ed7ecf45511ccba3d84af22
|
|
| MD5 |
512bb7601ab7bd252240330f323577c4
|
|
| BLAKE2b-256 |
418ecca7eccf3e232a7105d51e8a9c752c768d43bd45c4cc4a918e209ed82ec3
|
File details
Details for the file ongarde-1.0.0-py3-none-any.whl.
File metadata
- Download URL: ongarde-1.0.0-py3-none-any.whl
- Upload date:
- Size: 124.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f68c37c5a456bd7e72f9c40475c2adee1388d0875378160255dd11ee0ad4fe7b
|
|
| MD5 |
f595b08936408b1efc470604841e5a00
|
|
| BLAKE2b-256 |
f3500797338303a8f5c8e515f8d092de6e1f78746ac619ba31ec45deecb27924
|