Skip to content

Python client library and CLI for sandbox execution backends (NoxRunner spec), featuring local offline test mode and standard-library-only design.

License

Notifications You must be signed in to change notification settings

lzjever/noxrunner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

12 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ NoxRunner - Python Client for Sandbox Execution Backends

PyPI version Python 3.8+ License Documentation CI

NoxRunner is a Python client library for interacting with NoxRunner-compatible sandbox execution backends. It uses only Python standard library - zero external dependencies.

πŸ“– About This Project

NoxRunner is the client library extracted from Agentsmith, a commercial distributed, high-concurrency AI-Agent development and operating platform. In the commercial Agentsmith platform, sandboxes run on enterprise private cloud clusters with comprehensive security policies, operational standards, automated container management, image building, resource allocation, and content auditing capabilities. These enterprise features are not part of this open-source release.

What's Open Source:

  • βœ… Client Library: This Python client library for interacting with NoxRunner backends
  • βœ… Backend Specification: The complete API specification (see SPECS.md)
  • βœ… Local Sandbox Mode: A local device simulation mode for development, testing, and POC demos

Use Cases:

  • πŸ§ͺ Development & Testing: Use the local sandbox mode to develop and test AI agents without the overhead of managing a full cluster
  • πŸš€ Production Deployment: When ready to deploy publicly, switch to a real NoxRunner backend cluster for production workloads
  • πŸ”§ Mock Backend: Perfect for building simple AI agents that need a sandbox execution environment during development

This approach significantly reduces operational and debugging burden during the development phase while maintaining compatibility with production-grade sandbox infrastructure.

✨ Features

  • βœ… Zero Dependencies: Only uses Python standard library
  • βœ… Complete API Coverage: All NoxRunner backend endpoints
  • βœ… Shell Command Interface: Natural shell command execution with exec_shell() method
  • βœ… Environment Variable Support: Full support for environment variable expansion in shell commands
  • βœ… Friendly CLI: Colored output, interactive shell
  • βœ… Local Testing Mode: Offline testing with local sandbox backend
  • βœ… Easy to Use: Simple API with clear error messages
  • βœ… Well Documented: Comprehensive documentation and examples
  • βœ… Type Hints: Full type support for better IDE experience

πŸ“¦ Installation

Install from Source

# Clone the repository
git clone https://github.com/noxrunner/noxrunner.git
cd noxrunner

# Install in development mode
pip install -e .

# Or install with development dependencies
pip install -e ".[dev]"

Install from PyPI (when published)

pip install noxrunner

πŸš€ Quick Start

As a Library

from noxrunner import NoxRunnerClient

# Create client (local test mode for development)
client = NoxRunnerClient(local_test=True)

# Or connect to remote backend
# client = NoxRunnerClient("http://127.0.0.1:8080")

# Create sandbox
session_id = "my-session"
result = client.create_sandbox(session_id)
print(f"Sandbox: {result['podName']}")

# Wait for sandbox ready
client.wait_for_pod_ready(session_id)

# Execute command (array format)
result = client.exec(session_id, ["python3", "--version"])
print(result["stdout"])

# Execute shell command (string format - more natural!)
result = client.exec_shell(session_id, "python3 --version")
print(result["stdout"])

# Shell commands with environment variables
result = client.exec_shell(
    session_id,
    "echo $MY_VAR && ls -la",
    env={"MY_VAR": "test_value"}
)
print(result["stdout"])

# Upload files
client.upload_files(session_id, {
    "script.py": "print('Hello from NoxRunner!')"
})

# Download files as tar archive
tar_data = client.download_files(session_id)

# Download and extract to local directory (recommended)
import tempfile
from pathlib import Path

with tempfile.TemporaryDirectory() as tmpdir:
    client.download_workspace(session_id, tmpdir)
    # Files are now in tmpdir

# Delete sandbox
client.delete_sandbox(session_id)

As a CLI Tool

Remote Mode (Default):

# Health check
noxrc health

# Create sandbox
noxrc create my-session --wait

# Execute command
noxrc exec my-session python3 --version

# Upload files
noxrc upload my-session script.py data.txt

# Download files
noxrc download my-session --extract ./output

# Interactive shell
noxrc shell my-session

# Delete sandbox
noxrc delete my-session

Local Testing Mode (for offline testing):

# Use --local-test flag for offline testing
noxrc --local-test create my-session
noxrc --local-test exec my-session echo "Hello"
noxrc --local-test upload my-session script.py
noxrc --local-test delete my-session

⚠️ Warning: Local testing mode executes commands in your local environment using /tmp directories. This can cause data loss or security risks!

πŸ“š Documentation

πŸ—οΈ Project Structure

noxrunner/
β”œβ”€β”€ noxrunner/          # Python package
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ client.py       # NoxRunnerClient class
β”‚   β”œβ”€β”€ exceptions.py   # Exception classes
β”‚   β”œβ”€β”€ backend/        # Backend implementations
β”‚   β”‚   β”œβ”€β”€ base.py     # Abstract base class
β”‚   β”‚   β”œβ”€β”€ local.py    # LocalBackend
β”‚   β”‚   └── http.py     # HTTPSandboxBackend
β”‚   β”œβ”€β”€ security/        # Security utilities
β”‚   β”‚   β”œβ”€β”€ command_validator.py
β”‚   β”‚   └── path_sanitizer.py
β”‚   └── fileops/        # File operation utilities
β”‚       └── tar_handler.py
β”œβ”€β”€ tests/              # Test suite
β”‚   β”œβ”€β”€ test_security.py
β”‚   β”œβ”€β”€ test_fileops.py
β”‚   β”œβ”€β”€ test_backend_local.py
β”‚   β”œβ”€β”€ test_backend_http.py
β”‚   └── test_integration.py
β”œβ”€β”€ examples/           # Example scripts
β”œβ”€β”€ docs/               # Sphinx documentation
└── README.md           # This file

πŸ”Œ Backend Compatibility

NoxRunner is designed to work with any backend that implements the NoxRunner Backend Specification. This includes:

  • Kubernetes-based sandbox managers
  • Docker-based execution backends
  • VM-based sandbox systems
  • Any custom implementation following the spec

πŸ§ͺ Testing

# Run all unit tests
pytest tests/test_security.py tests/test_fileops.py tests/test_backend_local.py tests/test_backend_http.py

# Run local backend integration tests
pytest tests/test_integration.py::TestLocalBackendIntegration

# Run HTTP backend integration tests (requires running backend)
NOXRUNNER_ENABLE_INTEGRATION=1 NOXRUNNER_BASE_URL=http://127.0.0.1:8080 pytest tests/test_integration.py::TestHTTPSandboxBackendIntegration

# Run with coverage
pytest --cov=noxrunner --cov-report=html

# Run all tests
pytest tests/

Testing Modes

  • Unit Tests: Test individual modules (security, fileops, backend mocks)
  • Local Integration Tests: Test LocalBackend with real file operations
  • HTTP Integration Tests: Test HTTPSandboxBackend against running backend service

See USAGE.md for more details on testing.

πŸ“ License

MIT License - see LICENSE file for details.

🀝 Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

πŸ”— Links

πŸ™ Acknowledgments

NoxRunner was originally developed as part of Agentsmith, a commercial distributed AI-Agent development and operating platform. The client library and backend specification have been extracted and open-sourced to enable broader adoption and community contribution. The local sandbox simulation mode was added to facilitate development, testing, and POC demonstrations without requiring access to production infrastructure.

About

Python client library and CLI for sandbox execution backends (NoxRunner spec), featuring local offline test mode and standard-library-only design.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published