Skip to content

hackingsage/Agentic-AI-TEE

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ”’ Enclave β€” TEE-Protected AI Agent Platform

Your code, your data, your prompts β€” provably private. The AI helps you, but never learns from you.

Enclave is a privacy-first autonomous AI agent platform where all LLM inference and tool execution happens inside a Trusted Execution Environment (TEE). It cryptographically proves that user data, prompts, and task context never leave the secure enclave in plaintext.

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        USER BROWSER                          β”‚
β”‚           Next.js frontend  ←→  WebAuthn auth               β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                         β”‚ HTTPS + JWT
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                     GATEWAY LAYER (EC2 host)                 β”‚
β”‚   FastAPI  ─── SSE streaming ─── Task queue                  β”‚
β”‚   Attestation verifier        Audit log (append-only)        β”‚
└──────────────vsock─────────────────────────────────────────-β”€β”˜
                         β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                   β˜… NITRO ENCLAVE β˜…                          β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚
β”‚  β”‚             Agent Controller (Python)               β”‚    β”‚
β”‚  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚    β”‚
β”‚  β”‚  β”‚  Planner β”‚  β”‚ Executor β”‚  β”‚  Memory Manager   β”‚ β”‚    β”‚
β”‚  β”‚  β”‚ (Claude) β”‚  β”‚(sandbox) β”‚  β”‚ (sealed storage)  β”‚ β”‚    β”‚
β”‚  β”‚  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚    β”‚
β”‚  β”‚       β”‚             β”‚                  β”‚            β”‚    β”‚
β”‚  β”‚  β”Œβ”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚    β”‚
β”‚  β”‚  β”‚              Tool Router                        β”‚ β”‚    β”‚
β”‚  β”‚  β”‚  code_exec β”‚ file_ops β”‚ browser β”‚ api_call      β”‚ β”‚    β”‚
β”‚  β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚    β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚
β”‚  Enclave crypto keys (not accessible from host process)     β”‚
└──────────────vsock─────────────────────────────────────────-β”˜
                         β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                  PRIVACY PROXY (Go)                          β”‚
β”‚   Key rotation β”‚ Metadata stripping β”‚ Dummy-request padding β”‚
└──────────────mTLS──────────────────────────────────────────-β”˜
                         β”‚
              LLM Provider API (Anthropic / OpenAI)

Privacy Guarantees

Guarantee How It Works
TEE-enforced inference LLM API calls made from inside an attested AWS Nitro Enclave. The host cannot observe plaintext.
Attestation receipts Every task produces a signed attestation report proving code version, enclave identity, and data integrity.
Zero-training API calls route through a privacy proxy that strips metadata and rotates API keys.
Sealed memory Agent state encrypted with enclave-only keys derived from PCR measurements. Tampered enclaves lose access.
Task integrity SHA3-256 hash of every task's prompt + output included in the attestation receipt.

Quick Start

Prerequisites

  • Python 3.12+
  • Go 1.22+ (for the privacy proxy)

Setup

# Clone and enter the project
cd TEE

# Create virtual environment
python3 -m venv .venv
source .venv/bin/activate

# Install dependencies
pip install -e ".[dev]"

# Run tests
pytest tests/ -v

Run the Interactive TUI (Recommended)

Enclave includes a terminal interactive UI (TUI) that features real-time Claude Code-style token and event streaming (thinking steps, live text tokens, tool calls, and results) from the secure enclave:

source .venv/bin/activate
python tui.py

Inside the TUI, you can submit tasks, switch models/providers, inspect history, verify attestation receipts, and observe the agent's reasoning process in real-time.

Run the Host API (Development Gateway)

source .venv/bin/activate
uvicorn host.api.main:app --reload --port 8000

API Endpoints

Method Path Description
POST /tasks Submit a new task
GET /tasks/{id} Get task status
GET /tasks/{id}/stream SSE stream of task events
GET /tasks/{id}/attestation Get attestation receipt
GET /enclave/attest Get enclave attestation document
GET /health Health check

Project Structure

TEE/
β”œβ”€β”€ enclave/              # Runs inside the TEE
β”‚   β”œβ”€β”€ agent/            # AgentController, Planner, LLM client
β”‚   β”‚   β”œβ”€β”€ controller.py # Main agent step loop (native tool calling)
β”‚   β”‚   β”œβ”€β”€ planner.py    # System prompt builder (native tool use parameters)
β”‚   β”‚   β”œβ”€β”€ llm_client.py # Provider clients (Anthropic with streaming, OpenAI, etc.)
β”‚   β”‚   └── models.py     # All dataclasses (Message, ContentBlock, StepEvent, etc.)
β”‚   β”œβ”€β”€ tools/            # Tool implementations
β”‚   β”‚   β”œβ”€β”€ base.py       # BaseTool ABC + ToolRegistry (JSON tool definitions)
β”‚   β”‚   β”œβ”€β”€ router.py     # ToolRouter (dispatch + validation)
β”‚   β”‚   β”œβ”€β”€ code_executor.py
β”‚   β”‚   β”œβ”€β”€ file_ops.py
β”‚   β”‚   β”œβ”€β”€ browser_tool.py
β”‚   β”‚   β”œβ”€β”€ api_call.py
β”‚   β”‚   └── memory_tool.py
β”‚   β”œβ”€β”€ crypto/           # Cryptographic primitives
β”‚   β”‚   β”œβ”€β”€ keys.py       # Key generation, HKDF, SecretBox
β”‚   β”‚   β”œβ”€β”€ attestation.py # Nitro + Mock attestation providers
β”‚   β”‚   └── sealing.py    # PCR-bound secret sealing
β”‚   β”œβ”€β”€ memory/           # Persistent encrypted state
β”‚   β”‚   β”œβ”€β”€ manager.py    # MemoryManager (encrypted ChromaDB wrapper)
β”‚   β”‚   └── state_db.py   # TaskStateDB (async SQLite)
β”‚   └── vsock/            # Enclave ↔ Host communication
β”‚       β”œβ”€β”€ protocol.py   # Length-prefix message framing
β”‚       β”œβ”€β”€ server.py     # Async server (passes connection writer for streaming)
β”‚       └── client.py     # Async client (synchronous call & stream-iterator send)
β”œβ”€β”€ host/                 # Runs outside the TEE (untrusted)
β”‚   β”œβ”€β”€ api/main.py       # FastAPI gateway
β”‚   └── attestation/      # Host-side attestation verifier
β”œβ”€β”€ proxy/                # Go privacy proxy
β”œβ”€β”€ tests/                # Full test suite (114 tests)
β”œβ”€β”€ docs/                 # Security whitepaper, guides
└── pyproject.toml        # Project configuration

Security Model

Threat Model

  • Curious cloud provider: Cannot read Nitro Enclave memory
  • Compromised host: Can relay messages but cannot decrypt them
  • LLM provider: Cannot see plaintext prompts (privacy proxy strips metadata)
  • Network eavesdropper: All external traffic is mTLS
  • Malicious LLM responses: All tool calls sandboxed, validated against schema

Cryptographic Stack

  • Signing: Ed25519 (via libsodium/PyNaCl)
  • Encryption: XSalsa20-Poly1305 (NaCl SecretBox)
  • Key exchange: Curve25519 (NaCl SealedBox)
  • Key derivation: HKDF-SHA256
  • Attestation: AWS Nitro Attestation Document (COSE_Sign1 + CBOR)
  • Task integrity: SHA3-256

The North Star Test

"If Anthropic, AWS, or a government agency subpoenaed all logs, host process memory, and network traffic, what would they learn about the user's tasks?"

Answer: Nothing useful. They would see encrypted blobs, metadata-stripped API calls, and an attestation document proving legitimate code was running.

Development

Running Tests

pytest tests/ -v                              # All tests
pytest tests/ --cov=enclave --cov-report=term  # With coverage
pytest tests/test_agent_loop.py -v            # Agent loop only
pytest tests/test_attestation.py -v           # Crypto + attestation

Code Quality

ruff check enclave/ host/ tests/     # Linting
mypy enclave/ host/                   # Type checking
bandit -r enclave/ host/ -ll          # Security scanning

License

Private β€” All rights reserved.

About

Enclave is a privacy-first autonomous AI agent platform where all LLM inference and tool execution happens inside a Trusted Execution Environment (TEE). It cryptographically proves that user data, prompts, and task context never leave the secure enclave in plaintext.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages