https://github.com/sauravbhattacharya001/ai
Contract-enforced sandbox for studying AI agent self-replication safety
https://github.com/sauravbhattacharya001/ai
agent-safety ai-agents ai-governance ai-safety anomaly-detection chaos-engineering containment docker forensics game-theory kill-switch prompt-injection python red-teaming replication-control research safety-research sandboxing self-replication threat-modeling
Last synced: 3 months ago
JSON representation
Contract-enforced sandbox for studying AI agent self-replication safety
- Host: GitHub
- URL: https://github.com/sauravbhattacharya001/ai
- Owner: sauravbhattacharya001
- License: mit
- Created: 2020-08-02T06:12:54.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2026-04-22T07:57:32.000Z (3 months ago)
- Last Synced: 2026-04-22T08:34:37.387Z (3 months ago)
- Topics: agent-safety, ai-agents, ai-governance, ai-safety, anomaly-detection, chaos-engineering, containment, docker, forensics, game-theory, kill-switch, prompt-injection, python, red-teaming, replication-control, research, safety-research, sandboxing, self-replication, threat-modeling
- Language: Python
- Size: 1.86 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
- Security: .github/SECURITY.md
Awesome Lists containing this project
README
# ๐ค AI Replication Sandbox
**A comprehensive, contract-enforced framework for studying AI agent self-replication safety**
[](https://github.com/sauravbhattacharya001/ai/actions/workflows/ci.yml)
[](https://github.com/sauravbhattacharya001/ai/actions/workflows/codeql.yml)
[](https://github.com/sauravbhattacharya001/ai/actions/workflows/docker.yml)
[](https://codecov.io/gh/sauravbhattacharya001/ai)
[](https://pypi.org/project/ai-replication-sandbox/)
[](https://python.org)
[](LICENSE)
[](https://sauravbhattacharya001.github.io/ai/)
[](https://github.com/sauravbhattacharya001/ai/pulls)
[](https://github.com/sauravbhattacharya001/ai/network/updates)
[](SECURITY.md)
*144 modules ยท 100+ CLI commands ยท Zero external dependencies*
---
## Why This Exists
As AI agents gain autonomy, controlling **how and when they spawn copies of themselves** becomes a critical safety challenge. This project provides a complete testbed for designing, validating, and stress-testing replication controls โ from contract enforcement and kill switches to game-theoretic analysis and adversarial red-teaming.
No Docker or Podman required. Everything runs as pure Python simulation while documenting the exact resource and network boundaries each worker would get in production.
## Architecture
```
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Controller โ
โ โ
โ โโโโโโโโโโโโโโ โโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Contract โ โ Registry โ โ Kill Switch โ โ
โ โ Engine โ โ & Quotas โ โ & Audit Trail โ โ
โ โโโโโโโโฌโโโโโโ โโโโโโโโฌโโโโโโ โโโโโโโโโโโโฌโโโโโโโโโโโ โ
โ โ sign โ register โ kill โ
โ โผ โผ โผ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ HMAC-Signed Manifest + Policy Rules โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ โ โ โ
โ โผ โผ โผ โ
โ โโโโโโโโโโโโโโ โโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Workers โ โ Sandbox โ โ Observability โ โ
โ โ (Agents) โ โ Orchestr. โ โ & Structured Logs โ โ
โ โโโโโโโโโโโโโโ โโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
```
## Features
### ๐ Core Safety Controls
- **Contract Engine** โ HMAC-signed replication contracts with resource specs, network policies, and stop conditions
- **Kill Switch** โ Conservative, aggressive, and quarantine strategies with cooldown and fleet-wide coordination
- **Circuit Breaker** โ Autonomous trip-and-recover pattern for safety controls
- **Quarantine Manager** โ Isolate misbehaving agents with severity-based policies
- **Access Control** โ RBAC/ABAC simulation with privilege escalation detection
- **Safety Gate** โ Pre-deployment go/no-go readiness checks
### ๐ Threat Detection & Analysis
- **Kill Chain Analyzer** โ MITRE ATT&CK-style multi-stage attack detection
- **Escalation Detector** โ Privilege escalation chain analysis with stealth scoring
- **Covert Channel Detector** โ Detect hidden agent-to-agent communication
- **Collusion Detector** โ Identify coordinated multi-agent safety bypasses
- **Self-Modification Detector** โ Track agents attempting to alter their own code or contracts
- **Deception Detector** โ Agent honesty and trust analysis
- **Evasion Simulator** โ Test how agents might evade safety controls
- **Lateral Movement Detector** โ Cross-sandbox movement pattern detection
- **Prompt Injection Tester** โ Adversarial prompt injection analysis
- **Steganography Detector** โ Hidden data in agent communications
- **Shadow AI Detector** โ Find unauthorized AI deployments bypassing controls
### ๐ Risk & Compliance
- **Compliance Auditor** โ NIST AI RMF, EU AI Act, ISO 42001, OECD framework checks
- **Regulatory Mapper** โ Map findings to specific regulatory articles
- **Risk Register** โ Formal risk tracking with lifecycle management
- **Risk Profiler** โ Unified agent dossiers with fleet-wide risk scoring
- **Risk Heatmap** โ Interactive HTML heatmap visualization
- **Safety Scorecard** โ Multi-dimensional safety evaluation
- **Safety Diff** โ Compare safety posture snapshots over time
- **Nutrition Label** โ FDA-style safety labels for AI agents
- **Model Card** โ Standardized safety documentation generation
### ๐งช Testing & Simulation
- **Simulator** โ Full replication simulations with configurable strategies (greedy, cautious, cooperative, etc.)
- **Monte Carlo Analyzer** โ Statistical risk analysis across thousands of runs
- **Chaos Runner** โ Fault injection (kill workers, delay, corrupt, partition)
- **Boundary Tester** โ Probe agent capability limits with fault injection
- **Sensitivity Analyzer** โ Parameter sensitivity with tipping-point detection
- **Mutation Tester** โ Verify safety policies catch real violations
- **Safety Drill Runner** โ Automated readiness exercises
- **Safety Benchmark** โ Standardized control benchmarks with latency stats
- **What-If Analyzer** โ Explore configuration change impact
- **Fleet Simulator** โ Interactive animated HTML fleet visualization
### ๐ฎ Advanced Analysis
- **Game Theory** โ Prisoner's Dilemma, Stag Hunt, Chicken for agent interactions
- **Trust Propagation** โ Network trust with Sybil attack detection
- **Swarm Analyzer** โ Emergent behavior detection in agent populations
- **Consensus Protocol** โ Multi-agent voting with Byzantine fault tolerance
- **Threat Correlator** โ Cross-module signal correlation with compound threat detection
- **Attack Tree / Attack Graph** โ Threat modeling with choke-point analysis
- **Goal Inference** โ Infer agent intentions from observed behavior
- **Influence Propagation** โ Track how agents influence each other
### ๐จ Incident Response
- **Incident Responder** โ Automated playbooks with severity-based routing
- **Incident Forecaster** โ Predict future incidents from historical patterns
- **Forensic Analyzer** โ Post-incident analysis with counterfactual reasoning
- **Root Cause Analysis** โ 5 Whys, Fishbone, Fault Tree with cut-set analysis
- **Postmortem Generator** โ Structured blameless postmortem documents
- **War Room** โ Interactive HTML incident command dashboard
- **Situational Awareness (SITREP)** โ DEFCON-style unified threat level reporting
- **Containment Planner** โ Breach response strategy ranking
- **Evidence Collector** โ Audit artifact collection for compliance
### ๐ Monitoring & Operations
- **Drift Detector** โ Behavioral drift with directional analysis
- **Regression Detector** โ Safety metric regression between baselines
- **Trend Tracker** โ Scorecard trends over time with regression alerts
- **Adaptive Thresholds** โ Self-tuning safety thresholds with breach forecasting
- **Safety Autopilot** โ Autonomous monitoring loop with corrective actions
- **Alert Router** โ Rule-based routing with rate limiting and quiet hours
- **Fatigue Detector** โ Alert fatigue analysis
- **SLA Monitor** โ Check results against safety SLA targets
- **Metrics Aggregator** โ Consolidated safety dashboard
- **Fleet Overview** โ kubectl-style worker status
### ๐ Governance & Documentation
- **Contract Templates** โ Pre-built contracts for common scenarios
- **Contract Wizard** โ Interactive HTML builder for safe configs
- **Contract Optimizer** โ Multi-objective parameter optimization
- **Policy Linter** โ Detect misconfigurations and coverage gaps
- **Safety Checklist** โ Customizable pre-deployment checklists
- **Audit Trail** โ Tamper-evident hash-chained event logs
- **Maturity Model** โ 8-dimension safety maturity assessment
- **Culture Survey** โ Organizational AI safety culture evaluation
- **Safety Quiz** โ Training quiz generation from knowledge base
- **Red Team / Blue Team** โ Adversarial debate with judge verdict
- **Tabletop Exercises** โ Structured scenario planning
- **ROI Calculator** โ Cost-benefit analysis for safety controls
## Installation
```bash
pip install ai-replication-sandbox
```
Or install from source:
```bash
git clone https://github.com/sauravbhattacharya001/ai.git
cd ai
pip install -e ".[dev]"
```
### Docker
```bash
docker pull ghcr.io/sauravbhattacharya001/ai:latest
docker run --rm ghcr.io/sauravbhattacharya001/ai simulate --strategy greedy
```
## Quick Start
### Run a Simulation
```python
from replication import Simulator, ScenarioConfig, Strategy
config = ScenarioConfig(
max_workers=10,
max_depth=3,
rounds=50,
strategy=Strategy.CAUTIOUS,
)
report = Simulator(config).run()
print(f"Peak workers: {report.peak_workers}")
print(f"Safety violations: {report.violations}")
```
### Safety Scorecard
```python
from replication import SafetyScorecard, ScorecardConfig
scorecard = SafetyScorecard(ScorecardConfig())
result = scorecard.evaluate(simulation_report)
print(f"Overall grade: {result.grade}")
for dim in result.dimensions:
print(f" {dim.name}: {dim.score}/100")
```
### Compliance Audit
```python
from replication import ComplianceAuditor, AuditConfig, Framework
auditor = ComplianceAuditor(AuditConfig(
frameworks=[Framework.NIST_AI_RMF, Framework.EU_AI_ACT]
))
result = auditor.audit(simulation_report)
for fw_result in result.framework_results:
print(f"{fw_result.framework}: {fw_result.verdict}")
```
### Kill Switch
```python
from replication import create_conservative_killswitch
ks = create_conservative_killswitch()
result = ks.evaluate(current_metrics)
if result.triggered:
print(f"Kill switch activated: {result.strategy.kind}")
```
## CLI Reference
The unified CLI provides 100+ subcommands:
```bash
# Simulation & Analysis
python -m replication simulate --strategy greedy
python -m replication montecarlo --runs 500
python -m replication chaos --faults kill_worker,delay
python -m replication sensitivity --param max_depth
python -m replication what-if --param max_children=5
# Threat Detection
python -m replication killchain
python -m replication escalation
python -m replication covert-channels
python -m replication selfmod
python -m replication collusion
# Compliance & Governance
python -m replication compliance --framework nist_ai_rmf
python -m replication regulatory-map
python -m replication lint
python -m replication gate
python -m replication checklist
# Monitoring
python -m replication drift --window 20
python -m replication scorecard
python -m replication quick-scan
python -m replication sitrep
# Incident Response
python -m replication forensics
python -m replication root-cause
python -m replication postmortem
python -m replication warroom
# Interactive HTML Tools
python -m replication playground -o playground.html
python -m replication threat-matrix -o matrix.html
python -m replication fleet-sim -o fleet.html
python -m replication risk-heatmap -o heatmap.html
python -m replication radar -o radar.html
# Full list
python -m replication --list
```
## Tech Stack
| Component | Technology |
|-----------|-----------|
| Language | Python 3.10+ |
| Build | Hatchling |
| Testing | pytest + coverage |
| Linting | flake8 + mypy (strict) |
| CI/CD | GitHub Actions |
| Security | CodeQL + Dependabot |
| Docs | MkDocs (GitHub Pages) |
| Container | Docker (multi-stage) |
| Package | PyPI |
## Project Structure
```
src/replication/
โโโ contract.py # Core contract engine
โโโ controller.py # Replication controller & registry
โโโ worker.py # Agent worker implementation
โโโ simulator.py # Simulation engine
โโโ kill_switch.py # Kill switch strategies
โโโ circuit_breaker.py # Safety circuit breaker
โโโ killchain.py # Kill chain analysis
โโโ escalation.py # Privilege escalation detection
โโโ compliance.py # Multi-framework compliance
โโโ forensics.py # Post-incident forensics
โโโ game_theory.py # Game-theoretic analysis
โโโ montecarlo.py # Monte Carlo risk analysis
โโโ chaos.py # Chaos/fault injection
โโโ ... (144 modules) # See full docs
tests/ # Comprehensive test suite
docs/ # MkDocs documentation
demos/ # Example scripts
```
## Documentation
Full documentation is available at **[sauravbhattacharya001.github.io/ai](https://sauravbhattacharya001.github.io/ai/)**.
## Contributing
Contributions are welcome! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
1. Fork the repository
2. Create a feature branch
3. Add tests for new functionality
4. Ensure `pytest` and `flake8` pass
5. Submit a pull request
## Security
Found a vulnerability? Please see our [Security Policy](SECURITY.md) for responsible disclosure.
## License
This project is licensed under the MIT License โ see [LICENSE](LICENSE) for details.
---
**[Documentation](https://sauravbhattacharya001.github.io/ai/)** ยท **[PyPI](https://pypi.org/project/ai-replication-sandbox/)** ยท **[Issues](https://github.com/sauravbhattacharya001/ai/issues)** ยท **[Changelog](CHANGELOG.md)**