Skip to main content

nex-box ⚡

Sub-millisecond, zero-copy, kernel-level execution sandbox for autonomous coding agents.

PyPI version License Platform Rust

nex-box solves the fundamental dilemma of autonomous AI engineering: how to let coding agents run untrusted tests, builds, and destructive file mutations without risking host corruption or waiting seconds for Docker.

Backed by macOS APFS clonefile(2) and Linux ioctl(FICLONE) copy-on-write primitives, nex-box instantiates ephemeral scratch workspaces in under 3 milliseconds, traps all file mutations and network attempts at the kernel layer, and guarantees instant atomic rollback on failure or zero-copy promotion on success.


The Problem: The Agent Sandboxing Dilemma

When an AI agent (Cursor, Claude Code, Aider, custom autonomous loops) writes and tests software, developers are forced into bad compromises:

+-------------------+--------------------+---------------------------------------------------+
| APPROACH          | LATENCY            | FAILURE MODES & OPERATIONAL FRICTION              |
+-------------------+--------------------+---------------------------------------------------+
| Host Subprocess   | ~25ms              | Destructive file overwrites; leaks .env secrets;  |
|                   |                    | dirty cache pollution (.pytest_cache, .pyc).      |
+-------------------+--------------------+---------------------------------------------------+
| Docker Containers | 1,500ms – 3,500ms  | Heavy daemon requirement; multi-second latency    |
|                   |                    | kills agent flow state; complex volume mounts.    |
+-------------------+--------------------+---------------------------------------------------+
| Python venv / cp  | 150ms – 800ms      | Slow file copies; wears SSD endurance; no network |
|                   |                    | containment; fails to sandbox non-Python edits.   |
+-------------------+--------------------+---------------------------------------------------+
| nex-box (CoW)     | 2.1ms (2,168µs)    | Sub-millisecond APFS/FICLONE inode branching;     |
|                   |                    | atomic commit or instant purge; zero disk bloat.  |
+-------------------+--------------------+---------------------------------------------------+

Architectural Topology

                  HOST WORKSPACE (Pristine Inode Root)
                                   │
              ┌────────────────────┴────────────────────┐
              │ clonefile(2) / ioctl(FICLONE)            │ < 2.5ms Latency
              ▼                                         ▼
   EPHEMERAL SCRATCH ROOT                    KERNEL CONFINEMENT ENCLAVE
   (.nexbox/sessions/box_xxx)                 ├── macOS Seatbelt: (deny network*)
              │                               └── Linux: unshare(CLONE_NEWNET)
              ├─────────────────────────────────────────┤
              │ COMMAND EXECUTION & WATCHDOG TIMER      │
              │ ├── Scratch Log I/O (Anti-Pipe Lock)    │
              │ └── Hard millisecond SIGKILL watchdog   │
              ├─────────────────────────────────────────┤
              │ BLAKE3 CRYPTOGRAPHIC DIFFERENTIAL       │
              │ ├── Hashes only mutated file inodes     │
              │ └── Extracts: Created, Modified, Deleted│
              └────────────────────┬────────────────────┘
                                   │
                    ┌──────────────┴──────────────┐
                    ▼                             ▼
           EXIT CODE 0 & --commit        EXIT CODE != 0 / TIMEOUT
                    │                             │
                    ▼                             ▼
        [ATOMIC PROMOTION]               [AUTOMATIC ROLLBACK]
   Reflink changes to host tree.    Instant purge of scratch tree.
   Host updated in microseconds.    Host remains 100% untouched.

Installation

Via pip (Pre-compiled wheels for all major platforms)

pip install nex-box
# or with uv (recommended):
uv pip install nex-box

Via Cargo (Standalone binary)

cargo install nex-box

Quickstart

1. Python API (import nex_box)

nex-box ships a native PyO3 C-extension that hooks directly into any Python agentic framework:

import nex_box

# Run untrusted agent code in a 2ms CoW sandbox:
outcome = nex_box.run(
    command=["pytest", "tests/"],
    commit=True,          # Automatically commit to host ONLY if exit code == 0
    timeout_ms=5000,      # Hard watchdog kill after 5.0 seconds
    allow_net=False       # Kernel-level network socket isolation
)

if outcome.is_success():
    print(f"Verified in {outcome.duration_ms}ms!")
    print(f"Cloned in: {outcome.clone_duration_micros}µs")
    print(f"Files Created: {outcome.diff.files_created}")
    print(f"Files Modified: {outcome.diff.files_modified}")
else:
    print(f"Agent failed with exit code {outcome.exit_code}!")
    print("Host was untouched. Error trace:")
    print(outcome.stderr)

2. Standalone CLI (nex-box)

# 1. Ephemeral Dry Run (Default: Discards all mutations on exit)
nex-box run -- bash -c "echo 'mutation' > test.txt && pytest"

# 2. Atomic Commit (Promotes changes to host only if command succeeds)
nex-box run --commit -- python3 -m py_compile module.py

# 3. Watchdog Timeout Protection (Kills runaway infinite loops)
nex-box run --timeout-ms 2000 -- python3 -c "while True: pass"

# 4. Kernel Network Isolation (Denies all outbound TCP/UDP sockets)
nex-box run --allow-net false -- curl -I https://github.com

# 5. Machine-Readable JSON Telemetry (For agent stdout integration)
nex-box run --json -- echo "Agent complete"

Concrete Recipes for Coding Agents

Recipe 1: Safe Pytest Runner for Coding Agents

When agents run pytest, failed runs dirty your repository with .pytest_cache/, __pycache__, and half-written test artifacts. nex-box completely isolates them:

import nex_box

outcome = nex_box.run(
    command=["pytest", "tests/unit/"],
    commit=False,         # Throw away all pytest cache files and test debris
    timeout_ms=10000
)

# Output is captured cleanly; your git tree remains 100% pristine:
print(outcome.stdout)

Recipe 2: Air-Gapped Code Evaluation

Block outbound exfiltration or network dependencies at the operating system layer:

import nex_box

# On macOS, uses Apple Seatbelt ((deny network*)).
# On Linux, detaches the network namespace (unshare(CLONE_NEWNET)).
outcome = nex_box.run(
    command=["python3", "untrusted_script.py"],
    allow_net=False
)

Recipe 3: Atomic Multi-File Refactoring

Let an LLM refactor multiple files across your project. Promote the edits only if the build and lint passes:

import nex_box

outcome = nex_box.run(
    command=["bash", "-c", "ruff check . && cargo test"],
    commit=True,          # Atomic promotion: all or nothing
    timeout_ms=30000
)

if outcome.is_success():
    print("Refactor applied cleanly across files:", outcome.diff.files_modified)

Python API Reference

nex_box.run(...)

def run(
    command: list[str],
    cwd: str | None = None,
    commit: bool = False,
    timeout_ms: int = 60000,
    allow_net: bool = True,
    preserve: bool = False
) -> SandboxOutcome: ...

Parameters:

  • command (list[str]): The command line arguments to execute inside the scratch root (e.g. ["pytest", "tests/"]).
  • cwd (str | None): Base workspace directory to duplicate via CoW. Defaults to current working directory.
  • commit (bool): If True, automatically promotes all created/modified files back to cwd if and only if exit_code == 0. Default: False.
  • timeout_ms (int): Maximum wall-clock execution time in milliseconds before triggering hard SIGKILL. Default: 60000 (60s).
  • allow_net (bool): If False, denies all network sockets at the kernel level. Default: True.
  • preserve (bool): If True, preserves the .nexbox/sessions/ directory for manual inspection. Default: False.

Returns SandboxOutcome:

  • .exit_code (int): Process termination status code (e.g. 0, 1).
  • .duration_ms (int): Total process execution duration in milliseconds.
  • .clone_duration_micros (int): Time taken by the kernel to duplicate the entire directory tree (microseconds).
  • .files_cloned (int): Total file count mirrored into scratch space.
  • .committed (bool): Whether mutations were promoted back to the host filesystem.
  • .stdout (str): Standard output buffer.
  • .stderr (str): Standard error buffer.
  • .diff (WorkspaceDiff):
    • .diff.files_created (list[str]): Relative paths of files created in scratch.
    • .diff.files_modified (list[str]): Relative paths of existing files mutated.
    • .diff.files_deleted (list[str]): Relative paths of files removed.
    • .diff.elapsed_micros (int): Time taken by the in-memory BLAKE3 SIMD hash diff.

Technical Specifications

  1. Kernel CoW Engine (vfs_cow.rs):
    • macOS: Binds directly to libc::clonefile(2) on APFS. Creates copy-on-write pointers in the filesystem extent tree. Duplicating a 10,000-file repository takes $\le 4\text{ms}$ and consumes zero bytes of disk storage until mutated.
    • Linux: Invokes ioctl(dst_fd, FICLONE, src_fd) across Btrfs, XFS (reflink=1), and OpenZFS. Falls back to hardlinks or zero-allocation byte buffers.
  2. BLAKE3 SIMD Differential Engine (diff.rs):
    • Uses multi-threaded BLAKE3 tree hashing to compare file states between the host and scratch workspace. Detects exact byte mutations while automatically filtering OS noise (.DS_Store, .git).
  3. Pipe-Deadlock Immune Watchdog (sandbox.rs):
    • Child process stdout and stderr streams are redirected to scratch log files within the isolated inode space. This permanently neutralizes the 64KB POSIX pipe deadlock vulnerability where parent processes sleep while child processes block on filled pipe buffers.

License

Dual-licensed under either of:




Metadata

Release files for nex-box 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nex-box 0.1.1
File Size Uploaded Provenance Actions
nex_box-0.1.1.tar.gz 26.1 kB With provenance Details for nex_box-0.1.1.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for nex-box 0.1.1
File Actions
nex_box-0.1.1-cp312-cp312-manylinux_2_28_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.28+ x86-64 Details for nex_box-0.1.1-cp312-cp312-manylinux_2_28_x86_64.whl
nex_box-0.1.1-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details for nex_box-0.1.1-cp311-cp311-win_amd64.whl
nex_box-0.1.1-cp311-cp311-macosx_11_0_arm64.whl CPython 3.11 CPython 3.11 macOS 11.0+ ARM64 Details for nex_box-0.1.1-cp311-cp311-macosx_11_0_arm64.whl
nex_box-0.1.1-cp311-cp311-macosx_10_12_x86_64.whl CPython 3.11 CPython 3.11 macOS 10.12+ x86-64 Details for nex_box-0.1.1-cp311-cp311-macosx_10_12_x86_64.whl

Total release size: 1.1 MB

Release files / nex_box-0.1.1.tar.gz

Download URL nex_box-0.1.1.tar.gz
Size 26.1 kB
Tags Source
SHA-256 checksum
How to use checksums
e7195ea4acd2af6ab96b0b3002ba9f239bbf52d40872446f54bd620dd6744661
BLAKE2b-256 checksum
How to use checksums
08985507ec1d72355b6835aa18759d5ee8af604501e5c116bd75b26b43a31f31
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 28, 2026.

Transparency log

Release files / nex_box-0.1.1-cp312-cp312-manylinux_2_28_x86_64.whl

Download URL nex_box-0.1.1-cp312-cp312-manylinux_2_28_x86_64.whl
Size 298.3 kB
Tags CPython 3.12 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
02cee301e4d67f01a6f5725d0fb37534bd42d82ee285088e7789f55087beaedb
BLAKE2b-256 checksum
How to use checksums
a673c1929d499542e5913d62c8f60e7fa902c9f69caa5372c4e90ebcc60c86bc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 28, 2026.

Transparency log

Release files / nex_box-0.1.1-cp311-cp311-win_amd64.whl

Download URL nex_box-0.1.1-cp311-cp311-win_amd64.whl
Size 235.2 kB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
5081c1a28b370b3e5bdbef217f62fe517622942efcd60fb500710d4bfc8066f8
BLAKE2b-256 checksum
How to use checksums
fb90760bd47ad5361fb1ff0a52456d0827d9fbde66160d4f30da15a06e6e0374
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 28, 2026.

Transparency log

Release files / nex_box-0.1.1-cp311-cp311-macosx_11_0_arm64.whl

Download URL nex_box-0.1.1-cp311-cp311-macosx_11_0_arm64.whl
Size 256.1 kB
Tags CPython 3.11 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
1879bc0c5b6fcc53a344ca1f0bd79a4e407783796829a299a03032bf84b7bad4
BLAKE2b-256 checksum
How to use checksums
6642e3bdec957d4bc685771c78512cedeb82e20d7b5fd1c9ba3cb649862300a4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 28, 2026.

Transparency log

Release files / nex_box-0.1.1-cp311-cp311-macosx_10_12_x86_64.whl

Download URL nex_box-0.1.1-cp311-cp311-macosx_10_12_x86_64.whl
Size 282.1 kB
Tags CPython 3.11 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
af17f1e47de81f434fc661de4bbf16bacfc905f32f403c7dd8c1f59c3de63875
BLAKE2b-256 checksum
How to use checksums
2a3e3fa944fa247da3f2d8173b81d3b0e186a3174b7db39e730af5c8ab4d393b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 28, 2026.

Transparency log

Security for nex-box 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 5 files in this release have been uploaded with provenance metadata.

Select from 5 files

Attestation for nex_box-0.1.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 28, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page