Skip to main content

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

Python Support Package Status License: MIT CI Coverage

Documentation | Examples | PyPI (Coming Soon) | 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:

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.0: Enhanced pattern validation and error reporting
  • v0.4.0: Advanced caching and performance optimizations
  • v0.5.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

cryptex_ai-0.3.0.tar.gz (185.9 kB view details)

Uploaded Source

Built Distribution

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

cryptex_ai-0.3.0-py3-none-any.whl (31.1 kB view details)

Uploaded Python 3

File details

Details for the file cryptex_ai-0.3.0.tar.gz.

File metadata

  • Download URL: cryptex_ai-0.3.0.tar.gz
  • Upload date:
  • Size: 185.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for cryptex_ai-0.3.0.tar.gz
Algorithm Hash digest
SHA256 4fde7282a6261cb9444c5592a733fcfeef5fab203899a4ada7fb64eef064c17d
MD5 c5aa69df03cf1ef632a7334508227e09
BLAKE2b-256 74b5c349ea3d5b65a010b9fa9fe50e6d13c55785e8eb067552729818108af5fb

See more details on using hashes here.

Provenance

The following attestation bundles were made for cryptex_ai-0.3.0.tar.gz:

Publisher: release.yml on AnthemFlynn/cryptex-ai

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cryptex_ai-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: cryptex_ai-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 31.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for cryptex_ai-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 00079a88e5ab092e33080e961baa5ff1ba7c824b0fd4890e9eff4d9dfc886dfb
MD5 f95ef98e8e00c272929f9de75beab23e
BLAKE2b-256 681896db0f61ba8381efe3384da403f76e27b74c3f0c4b656ff424bbf827df4e

See more details on using hashes here.

Provenance

The following attestation bundles were made for cryptex_ai-0.3.0-py3-none-any.whl:

Publisher: release.yml on AnthemFlynn/cryptex-ai

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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