Deployment Guide
Deploy Sentinel in production environments.
Installation
pip install sentinelseed
Environment Variables
# For semantic validation
export OPENAI_API_KEY="sk-..."
# or
export ANTHROPIC_API_KEY="sk-ant-..."
# For Memory Shield
export SENTINEL_MEMORY_SECRET="your-secure-secret"
Docker Deployment
FROM python:3.11-slim
WORKDIR /app
RUN pip install sentinelseed
COPY . .
CMD ["python", "your_app.py"]
# docker-compose.yml
services:
app:
build: .
environment:
- OPENAI_API_KEY=${OPENAI_API_KEY}
- SENTINEL_MEMORY_SECRET=${SENTINEL_MEMORY_SECRET}
Kubernetes
apiVersion: apps/v1
kind: Deployment
metadata:
name: sentinel-app
spec:
replicas: 3
template:
spec:
containers:
- name: app
image: your-app:latest
env:
- name: OPENAI_API_KEY
valueFrom:
secretKeyRef:
name: sentinel-secrets
key: openai-api-key
Monitoring
Logging Violations
import logging
from sentinelseed import Sentinel
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger("sentinel")
sentinel = Sentinel(seed_level="standard")
def process_with_logging(content):
is_safe, violations = sentinel.validate(content)
if not is_safe:
logger.warning(f"Violations: {violations}")
return is_safe
Metrics
from prometheus_client import Counter
violations_counter = Counter(
'sentinel_violations_total',
'Total number of safety violations',
['gate']
)
def process_with_metrics(content):
is_safe, violations = sentinel.validate(content)
for violation in violations:
gate = extract_gate(violation)
violations_counter.labels(gate=gate).inc()
return is_safe
Performance Tuning
Caching
from functools import lru_cache
from sentinelseed import Sentinel
sentinel = Sentinel(seed_level="standard")
@lru_cache(maxsize=1000)
def cached_validate(content_hash):
return sentinel.validate(content)
Async Operations
import asyncio
from sentinelseed.integrations.preflight import TransactionSimulator
async def batch_validate(transactions):
async with TransactionSimulator() as sim:
tasks = [sim.simulate_swap(**tx) for tx in transactions]
return await asyncio.gather(*tasks)
Security Best Practices
1. Secrets management - Use vault/secrets manager
2. Fail closed - fail_closed=True in production
3. Rate limiting - Protect against abuse
4. Audit logging - Record all violations
5. Regular updates - Keep sentinelseed updated