Skip to main content

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.

Python FastAPI License Tests


What It Does

OnGarde sits between your AI agent and the LLM provider. Zero code changes required โ€” just point your baseUrl at OnGarde.

OnGarde Architecture

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)

What OnGarde Blocks

Fail-safe: errors and timeouts default to BLOCK โ€” security over availability.


Quick Start

Get Started in 3 Steps

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_key field 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. The npx @ongarde/openclaw init wizard 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: false for 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


Contributing

Issues and PRs welcome. Please open an issue before starting significant work so we can discuss direction.


License

MIT โ€” see LICENSE.


Links

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ongarde-1.0.0.tar.gz (106.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ongarde-1.0.0-py3-none-any.whl (124.6 kB view details)

Uploaded Python 3

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

Hashes for ongarde-1.0.0.tar.gz
Algorithm Hash digest
SHA256 69cd2ccaf07b42798c948006d40ad747e9207ecb0ed7ecf45511ccba3d84af22
MD5 512bb7601ab7bd252240330f323577c4
BLAKE2b-256 418ecca7eccf3e232a7105d51e8a9c752c768d43bd45c4cc4a918e209ed82ec3

See more details on using hashes here.

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

Hashes for ongarde-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f68c37c5a456bd7e72f9c40475c2adee1388d0875378160255dd11ee0ad4fe7b
MD5 f595b08936408b1efc470604841e5a00
BLAKE2b-256 f3500797338303a8f5c8e515f8d092de6e1f78746ac619ba31ec45deecb27924

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page