Metadata-Version: 2.4
Name: nephis
Version: 1.0.0
Summary: NEPHIS: High-Throughput Isolated Execution Substrate & Zero-Copy Database Branching for AI Agents
Home-page: https://nephis.theeducode.com
Author: Mohit Raj Deo
Author-email: Mohit Raj Deo <mohit@mohitrajdeo.in>
License: Apache-2.0
Project-URL: Homepage, https://nephis.theeducode.com
Project-URL: Documentation, https://nephis.theeducode.com
Project-URL: Repository, https://github.com/mohitrajdeo/ciel-Aletheia
Project-URL: Author, https://mohitrajdeo.in
Keywords: nephis,microvm,sandbox,mcp,ai-agents,code-evaluation,judge0-alternative,database-branching
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: POSIX :: Linux
Classifier: Operating System :: Microsoft :: Windows
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: License :: OSI Approved :: Apache Software License
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: requests>=2.28.0
Provides-Extra: dev
Requires-Dist: pytest>=7.0.0; extra == "dev"
Dynamic: author
Dynamic: home-page
Dynamic: license-file
Dynamic: requires-python

# NEPHIS (Python SDK)

> **Official Python SDK for NEPHIS Systems Fabric**  
> Sub-6ms Hardware-Isolated MicroVM Sandboxes, Zero-Copy PostgreSQL Branching, and Bare-Metal Code Execution for Autonomous AI Agents.

[![Python Version](https://img.shields.io/badge/python-3.8%2B-blue.svg)](https://www.python.org/)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE)
[![Zero Dependencies](https://img.shields.io/badge/dependencies-0%20(urllib%20std)-green)](thanaton/client.py)

---

## ⚡ What is Thanaton?

**Thanaton** is a high-performance execution engine built on **Firecracker MicroVMs**, **Userfaultfd lazy memory paging**, and **cgroups v2 jailers**. It allows AI agents and developers to boot full-featured Linux environments in single-digit milliseconds, execute untrusted code safely with KVM hardware isolation, and scale to zero at $0 idle cost.

### Thanaton vs. The Competition

| Feature | Docker | E2B / Modal | AWS Lambda | **Thanaton** |
| :--- | :---: | :---: | :---: | :---: |
| **Cold Boot Latency** | 2s – 10s | 150ms – 400ms | 200ms – 1.5s | **< 6.14ms (< 2ms with UFFD)** ⚡ |
| **Isolation Tier** | Shared Host Kernel | Container Sandbox | MicroVM | **Hardware KVM Hypervisor** 🔒 |
| **Scale-to-Zero ($0 Cost)** | ❌ Memory tied up | ❌ Billed per second | ✅ (Stateless only) | **✅ Memory Snapshot (0 MB RAM)** 💾 |
| **Embedded PostgreSQL** | ❌ Manual Dockerfile | ❌ None | ❌ None | **✅ Instant Bundled Postgres (10ms)** 🗄️ |
| **Dependency Footprint** | Heavy Daemon | Heavy PyPI deps | AWS SDK bloat | **✅ Zero External Dependencies** 🪶 |

---

## 🏆 Dual-Hardware Physical Benchmark Matrix (AWS Mumbai `ap-south-1b`)
Tested across bare-metal-equivalent AWS EC2 instances:
* **Host 1 (AMD64):** `c8i.large` (Intel Xeon 6975P-C @ 3.8 GHz Turbo, 2 vCPUs, 4 GB RAM, Linux `7.0.0-1014-aws`)
* **Host 2 (ARM64):** `c8g.large` (AWS Graviton4 Neoverse-V2 @ 2.6 GHz, 2 vCPUs, 4 GB RAM, Linux `7.0.0-1014-aws`)

| Subsystem / Metric | Intel Xeon 6 (AMD64) | AWS Graviton4 (ARM64) | Physical Winner | Hardware Root Cause |
| :--- | :--- | :--- | :--- | :--- |
| **Thanaton MicroVM Sandbox** | **32.74 ms** (Python 1M sum) | 39.96 ms | **AMD64 (+18.1%)** | Raw single-thread interpreter cycle throughput |
| **Mnemon-DB 12 Reflink Clusters** | 50.81 ms | **31.67 ms** | **ARM64 (+37.7%)** | XFS extent allocation concurrency on NVMe |
| **Eschaton Parallel Fan-Out** | **38.2 ms** (50 testcases) | 41.5 ms (50 testcases) | **AMD64 (70x vs Judge0)** | Bare-metal parallel worker fan-out vs sequential Docker |
| **Hyperion Task Dispatch** | **5,290,366 tasks/s** | 3,052,964 tasks/s | **AMD64 (+42.3%)** | SCX eBPF ring buffer enqueue loop latency |
| **Hyperion NVMe I/O QoS Clamping** | **17 µs (96% drop)** | **17 µs (96% drop)** | **Parity** | Clamps rogue noisy-neighbor I/O from 3,850 µs to 155 µs |
| **Acheron Stream Compression** | 3,631.2 MB/s (Snappy) | **4,870.6 MB/s (LZ4)** | **ARM64 (+274.4%)** | ARM NEON vector instruction throughput |
| **Lethe DuckDB Columnar OLAP** | 177.5M rows/s (1.32 GB/s) | **276.9M rows/s (2.06 GB/s)** | **ARM64 (+56.0%)** | Graviton4 DDR5 memory bandwidth & vector registers |

---

## 🎁 Free Tier & Enterprise Deployment Models

* **Free Alpha Tier:** 10,000 free evaluation runs on our dedicated endpoint so you can benchmark your reasoning rollouts immediately.
* **AWS Marketplace AMI:** 1-click pre-baked AMI deployment directly into your private AWS VPC.
* **On-Premise / BYOC (Bring Your Own Cloud):** Deploy onto your own bare-metal servers or cloud VPC with zero external dependencies.
* **Fully Managed Dedicated SaaS:** High-availability cluster with sub-50ms execution SLA.

> **Direct Contact for All Upgrades, Custom AMIs & Enterprise Licensing:**  
> Email: **`mohit@mohitrajdeo.in`**

---

## 📦 Installation

```bash
pip install nephis
```

*Or install from source:*
```bash
git clone https://github.com/MOHITRAJDEO12345/judge0-production-aws.git
cd judge0-production-aws/sdk/python
pip install -e .
```

---

## 🚀 Quickstart

### 1. Ephemeral Code Execution (One-Liner)

```python
import thanaton

client = thanaton.Client()

result = client.run_code("""
import numpy as np
arr = np.array([1, 2, 3, 4, 5])
print("Mean:", arr.mean())
""", language="python")

print(result.stdout)       # "Mean: 3.0"
print(f"Exit code: {result.exit_code}")
print(f"Executed in: {result.duration_ms}ms")
```

---

### 2. Context Manager with Embedded PostgreSQL

```python
import thanaton

client = thanaton.Client(
    base_url="http://127.0.0.1:8080",
    api_key="thanaton_sec_..."  # optional for authenticated SaaS
)

# Provision a 512MB MicroVM with an embedded PostgreSQL database
with client.sandboxes.create(runtime="microvm", memory_mb=512, with_db=True) as sbx:
    print(f"Sandbox ID: {sbx.id} (Booted in {sbx.boot_duration_ms:.2f}ms)")
    print(f"PostgreSQL URL: {sbx.db_url}")

    # 1. Execute bash commands inside the MicroVM
    res = sbx.exec("pip install -q pandas scikit-learn")
    print("Pip stdout:", res.stdout)

    # 2. Run SQL queries against the embedded database
    sbx.sql("CREATE TABLE metrics (id SERIAL PRIMARY KEY, metric_name TEXT, score FLOAT);")
    sbx.sql("INSERT INTO metrics (metric_name, score) VALUES ('accuracy', 0.985);")
    rows = sbx.sql("SELECT * FROM metrics;")
    print("Database Rows:", rows)

    # 3. Scale to Zero (Hibernates to NVMe snapshot; 0% CPU, $0 idle RAM)
    sbx.sleep()
    print("Sandbox state:", sbx.state)  # "sleeping"

    # 4. Instant Wake (<2ms Userfaultfd restore)
    sbx.wake()
    print("Sandbox state:", sbx.state)  # "running"
```

---

## 🤖 AI Agent Framework Integrations

### CrewAI Integration

```python
from crewai.tools import tool
import thanaton

client = thanaton.Client()

@tool("Thanaton MicroVM Sandbox")
def execute_code_safely(code: str, language: str = "python") -> str:
    """Execute arbitrary untrusted Python, Node, or Bash code in an isolated KVM MicroVM."""
    res = client.run_code(code, language=language)
    if res.ok:
        return res.stdout
    return f"Execution Error (exit {res.exit_code}):\n{res.stderr}"
```

### LangChain Integration

```python
from langchain_core.tools import tool
import thanaton

client = thanaton.Client()

@tool
def thanaton_code_executor(code: str) -> str:
    """Runs Python code safely in a sub-6ms Firecracker MicroVM."""
    res = client.run_code(code, language="python")
    return res.stdout or res.stderr
```

---

## ⚙️ Environment Variables

| Variable | Description | Default |
| :--- | :--- | :--- |
| `THANATON_API_URL` | Endpoint of the Thanaton Engine or Control Plane | `http://127.0.0.1:8080` |
| `THANATON_API_KEY` | Bearer token for SaaS authorization | `""` |

---

## 📄 License

Apache-2.0 © Thanaton Architecture Team
