Zero-config temporal isolation for AI/LLM applications - Bulletproof secrets isolation with zero cognitive overhead
Project description
Cryptex-AI
Zero-config temporal isolation for AI/LLM applications
Bulletproof secrets isolation with zero cognitive overhead
Documentation | Examples | PyPI | Changelog
The Problem
AI/LLM applications face an impossible choice:
- Expose secrets to AI โ Security nightmare ๐
- Hide secrets completely โ Broken functionality ๐ฅ
The Solution
Cryptex-ai provides temporal isolation - AI sees safe placeholders while your code gets real secrets.
from cryptex_ai import protect_secrets
# Works immediately - no config files required!
@protect_secrets(["openai_key"])
async def ai_tool(prompt: str, api_key: str) -> str:
# AI sees: ai_tool("Hello", "{{OPENAI_API_KEY}}")
# Function gets: real API key for execution
return await openai_call(prompt, api_key)
One decorator line = complete temporal isolation โจ
๐ Key Features
- ๐ง Zero Configuration: Works immediately, no setup required
- โก Built-in Patterns: OpenAI, Anthropic, GitHub, file paths, databases
- ๐ก๏ธ Security First: Zero dependencies, no config files, no parsing vulnerabilities
- ๐ High Performance: <5ms sanitization, <10ms resolution
- ๐ Universal: Works with any Python function - FastMCP, FastAPI, Django, Flask, etc.
- ๐ Simple API: 95% of users need zero config, 5% get simple registration
๐ฆ Installation
Using pip (recommended)
pip install cryptex-ai
Using uv (modern Python package manager)
uv add cryptex-ai
Requirements: Python 3.11+ โข Zero dependencies
โก Quick Start
Zero-Config Protection (95% of users)
Cryptex works immediately with built-in patterns for common secrets:
from cryptex_ai import protect_secrets
# Protect OpenAI API calls
@protect_secrets(["openai_key"])
async def ai_completion(prompt: str, api_key: str) -> str:
# AI context: "{{OPENAI_API_KEY}}"
# Function execution: "sk-real-key-here..."
return await openai.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": prompt}],
api_key=api_key
)
# Protect file operations
@protect_secrets(["file_path"])
async def read_file(file_path: str) -> str:
# AI context: "/{USER_HOME}/.../{filename}"
# Function execution: "/Users/alice/secrets/document.txt"
with open(file_path, 'r') as f:
return f.read()
# Protect multiple secrets at once
@protect_secrets(["github_token", "file_path", "database_url"])
async def process_data(repo_path: str, token: str, db_url: str) -> dict:
# All secrets automatically protected
data = await fetch_from_github(repo_path, token)
result = await process_ai_data(data)
await save_to_database(result, db_url)
return result
Convenience Decorators
For common patterns, use convenience decorators:
from cryptex_ai import protect_api_keys, protect_files, protect_all
@protect_api_keys() # Protects OpenAI + Anthropic keys
async def ai_function(openai_key: str, anthropic_key: str) -> str:
# Both API keys automatically protected
pass
@protect_files() # Protects file system paths
async def file_function(file_path: str) -> str:
# File paths automatically protected
pass
@protect_all() # Protects all built-in patterns
async def comprehensive_function(api_key: str, file_path: str, db_url: str) -> str:
# Everything automatically protected
pass
๐ ๏ธ Built-in Patterns
Cryptex includes battle-tested patterns that handle 95% of real-world usage:
| Pattern | Detects | Example | Placeholder |
|---|---|---|---|
openai_key |
OpenAI API keys | sk-... |
{{OPENAI_API_KEY}} |
anthropic_key |
Anthropic API keys | sk-ant-... |
{{ANTHROPIC_API_KEY}} |
github_token |
GitHub tokens | ghp_... |
{{GITHUB_TOKEN}} |
file_path |
User file paths | /Users/..., /home/... |
/{USER_HOME}/.../{filename} |
database_url |
Database URLs | postgres://..., mysql://... |
{{DATABASE_URL}} |
No configuration required - patterns work out of the box! ๐ฆ
๐ง Custom Patterns (Advanced - 5% of users)
For edge cases, register custom patterns programmatically:
from cryptex_ai import register_pattern, protect_secrets
# Register custom pattern once
register_pattern(
name="slack_token",
regex=r"xoxb-[0-9-a-zA-Z]{51}",
placeholder="{{SLACK_TOKEN}}",
description="Slack bot token"
)
# Use immediately in decorators
@protect_secrets(["slack_token"])
async def slack_integration(token: str) -> str:
return await slack_api_call(token)
# Bulk registration
from cryptex_ai import register_patterns
register_patterns([
("discord_token", r"[MNO][A-Za-z\d]{23}\.[\w-]{6}\.[\w-]{27}", "{{DISCORD_TOKEN}}"),
("custom_key", r"myapp-[a-f0-9]{32}", "{{CUSTOM_KEY}}")
])
๐๏ธ Framework Examples
FastMCP Tools
from fastmcp import FastMCPServer
from cryptex_ai import protect_secrets
server = FastMCPServer("my-server")
@server.tool()
@protect_secrets(["openai_key"])
async def ai_tool(prompt: str, api_key: str) -> str:
# MCP sees: ai_tool("Hello", "{{OPENAI_API_KEY}}")
# Tool gets: real API key for execution
return await openai_call(prompt, api_key)
FastAPI Endpoints
from fastapi import FastAPI
from cryptex_ai import protect_secrets
app = FastAPI()
@app.post("/api/process")
@protect_secrets(["database_url", "openai_key"])
async def process_endpoint(data: dict, db_url: str, api_key: str):
# Request/response logs show placeholders
# Endpoint gets real secrets for execution
return await process_with_secrets(data, db_url, api_key)
Django Views
from django.http import JsonResponse
from cryptex_ai import protect_secrets
@protect_secrets(["database_url"])
async def django_view(request, db_url: str):
# Django logs show placeholders
# View gets real database URL
return JsonResponse(await query_database(db_url))
Any Python Function
from cryptex_ai import protect_secrets
@protect_secrets(["github_token"])
def sync_function(token: str) -> str:
# Works with sync functions too!
return github_api_call(token)
@protect_secrets(["openai_key"])
async def async_function(api_key: str) -> str:
# And async functions
return await openai_call(api_key)
โก Performance
Cryptex is designed for production workloads:
| Metric | Performance | Context |
|---|---|---|
| Sanitization | <5ms | 1KB payloads |
| Resolution | <10ms | 10 placeholders |
| Memory Overhead | <5% | vs unprotected apps |
| Startup Time | 0ms | Zero dependencies |
| Throughput | >1000 req/s | Typical workloads |
Benchmarked on MacBook Pro M1, Python 3.11
๐๏ธ Architecture
Three-Phase Temporal Isolation
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ Raw Secrets โ โ AI Processing โ โ Tool Execution โ
โ โ โ โ โ โ
โ sk-abc123... โโโโโถโ {{OPENAI_KEY}} โโโโโถโ sk-abc123... โ
โ /Users/alice/ โ โ /{USER_HOME}/ โ โ /Users/alice/ โ
โ ghp_xyz789... โ โ {{GITHUB_TOKEN}} โ โ ghp_xyz789... โ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
Phase 1: Phase 2: Phase 3:
Sanitization AI sees safe Resolution for
for AI context placeholders tool execution
Zero-Config Philosophy
- ๐ซ No Attack Surface: No config files to inject, no parsing to exploit
- โก Lightning Fast: Zero file I/O, zero parsing overhead
- ๐ฏ Middleware Focused: Lightweight, predictable, zero dependencies
- ๐จโ๐ป Developer Friendly: Works immediately, no setup friction
- ๐ Security First: Configuration in version-controlled code only
๐ Examples
Explore comprehensive examples in the examples/ directory:
- Basic Usage: Zero-config protection patterns
- FastAPI Integration: Web API protection
- Real World Usage: Complex multi-pattern scenarios
Run examples locally:
git clone https://github.com/AnthemFlynn/cryptex-ai.git
cd cryptex-ai
python examples/basic_usage.py
๐ก๏ธ Security
Cryptex follows security-first principles:
- Zero Dependencies: No external packages, no supply chain attacks
- Zero Config Files: No TOML parsing, no injection attacks
- Minimal Attack Surface: No file I/O, pure Python standard library
- Secure by Default: Built-in patterns tested against real-world secrets
- Audit Trail: Full temporal isolation with context tracking
- Pattern Validation: Runtime regex validation and comprehensive error handling
Security Policy: See SECURITY.md for vulnerability reporting.
๐งช Testing
Using pip
# Install dependencies
pip install -e ".[dev]"
# Run test suite
make test
# Run with coverage
make test-coverage
# Performance benchmarks
make test-performance
# Security tests
make test-security
Using uv
# Install dependencies
uv sync --dev
# Run test suite
uv run make test
# Run with coverage
uv run make test-coverage
# Performance benchmarks
uv run make test-performance
# Security tests
uv run make test-security
๐ค Contributing
We welcome contributions! Cryptex follows a zero-config philosophy - keep it simple.
Quick Development Setup
# Install uv first (if not already installed)
curl -LsSf https://astral.sh/uv/install.sh | sh
# Clone and set up the project
git clone https://github.com/AnthemFlynn/cryptex-ai.git
cd cryptex-ai
make dev-setup # Creates venv and installs dependencies with uv
make test # Run test suite
make lint # Code quality checks
make format # Code formatting
Development Guidelines
- Zero-Config First: No configuration files in middleware libraries
- Security First: Every change requires security review
- Performance Matters: <5ms sanitization, <10ms resolution
- Test Everything: Every bug gets a test, every feature gets tests
- SOLID Principles: Clean architecture and abstractions
See CONTRIBUTING.md for detailed guidelines.
๐ Roadmap
- v0.3.1 โ : Repository migration, documentation site, CI/CD improvements
- v0.4.0: Enhanced pattern validation and error reporting
- v0.5.0: Advanced caching and performance optimizations
- v0.6.0: Plugin system for custom secret sources
- v1.0.0: Production hardening and stability guarantees
๐ License
MIT License - see LICENSE file for details.
๐ Acknowledgments
- FastMCP Community: For excellent MCP server patterns
- FastAPI: For inspiring clean API design
- Python Community: For async/await and type system excellence
- Security Researchers: For temporal isolation concepts
Made with โค๏ธ for the AI/LLM community
โญ Star us on GitHub | ๐ Read the Docs | ๐ฌ Join Discussions
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
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 cryptex_ai-0.3.2.tar.gz.
File metadata
- Download URL: cryptex_ai-0.3.2.tar.gz
- Upload date:
- Size: 189.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
392fb42401c3805f325a5e9134ed24766d78afe7587ee40f592a621c601f7ddf
|
|
| MD5 |
f6afe25effe5d11a71c4f3223f24e58d
|
|
| BLAKE2b-256 |
8ecacc5b1f2081ccf83a4f79df9eb5e34544f1d6737b0d4bc013d801ed99cc56
|
Provenance
The following attestation bundles were made for cryptex_ai-0.3.2.tar.gz:
Publisher:
release.yml on AnthemFlynn/cryptex-ai
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cryptex_ai-0.3.2.tar.gz -
Subject digest:
392fb42401c3805f325a5e9134ed24766d78afe7587ee40f592a621c601f7ddf - Sigstore transparency entry: 291535385
- Sigstore integration time:
-
Permalink:
AnthemFlynn/cryptex-ai@7c6e5274742fad62a77f86d2a4ff5f0a9f748d25 -
Branch / Tag:
refs/tags/v0.3.2 - Owner: https://github.com/AnthemFlynn
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@7c6e5274742fad62a77f86d2a4ff5f0a9f748d25 -
Trigger Event:
push
-
Statement type:
File details
Details for the file cryptex_ai-0.3.2-py3-none-any.whl.
File metadata
- Download URL: cryptex_ai-0.3.2-py3-none-any.whl
- Upload date:
- Size: 32.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
517d3092e663d61b382542f8c92496e4622993553878a135d1a45ef69a159bb4
|
|
| MD5 |
b53a9ec68a04bb04d0c2a547e3c5c157
|
|
| BLAKE2b-256 |
11c7ceb330e5166034045c6870982bcdafc30fe74078918b8879203ce8e2784f
|
Provenance
The following attestation bundles were made for cryptex_ai-0.3.2-py3-none-any.whl:
Publisher:
release.yml on AnthemFlynn/cryptex-ai
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cryptex_ai-0.3.2-py3-none-any.whl -
Subject digest:
517d3092e663d61b382542f8c92496e4622993553878a135d1a45ef69a159bb4 - Sigstore transparency entry: 291535404
- Sigstore integration time:
-
Permalink:
AnthemFlynn/cryptex-ai@7c6e5274742fad62a77f86d2a4ff5f0a9f748d25 -
Branch / Tag:
refs/tags/v0.3.2 - Owner: https://github.com/AnthemFlynn
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@7c6e5274742fad62a77f86d2a4ff5f0a9f748d25 -
Trigger Event:
push
-
Statement type: