Skip to main content

nsjail-python

Python wrapper for Google's nsjail sandboxing tool

PyPI Python Version License: MIT

Installation

# Core library only (expects nsjail on PATH or installed separately)
pip install nsjail-python

# Include pre-built nsjail binary (Linux x86_64/aarch64)
pip install nsjail-python[binary]

# Build nsjail from source during install (needs gcc, make, protoc, etc.)
pip install nsjail-python[build]

# Add protobuf validation support
pip install nsjail-python[proto]

Quick Start

Low-level: NsJailConfig dataclass

from nsjail import NsJailConfig, MountPt, Exe

cfg = NsJailConfig(
    hostname="sandbox",
    time_limit=30,
    mount=[MountPt(src="/", dst="/", is_bind=True, rw=False)],
    exec_bin=Exe(path="/bin/sh", arg=["-c", "echo hello"]),
)

Mid-level: sandbox() preset

from nsjail import sandbox

cfg = sandbox(
    command=["python", "script.py"],
    memory_mb=512,
    timeout_sec=60,
    writable_dirs=["/workspace", "/tmp"],
)

High-level: Jail() fluent builder

from nsjail import Jail

cfg = (
    Jail()
    .sh("pytest tests/ -v")
    .memory(512, "MB")
    .timeout(60)
    .readonly_root()
    .writable("/workspace")
    .writable("/tmp", tmpfs=True, size="64M")
    .no_network()
    .build()
)

Serialization

from nsjail.serializers import to_textproto, to_cli_args, to_file

# Protobuf text format (for --config flag)
print(to_textproto(cfg))

# CLI arguments
args = to_cli_args(cfg, on_unsupported="skip")

# Write to file
to_file(cfg, "sandbox.cfg")

Running nsjail

from nsjail import Runner, Jail

runner = Runner(
    base_config=Jail()
        .command("python", "-m", "pytest")
        .memory(512, "MB")
        .timeout(300)
        .readonly_root()
        .writable("/workspace")
        .build(),
)

result = runner.run(extra_args=["tests/unit/", "-x"])
print(result.returncode, result.stdout)

Documentation

Full documentation is available at nsjail-python.readthedocs.io.

License

MIT

Metadata

Release files for nsjail-python 0.5.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 nsjail-python 0.5.1
File Size Uploaded Provenance
nsjail_python-0.5.1.tar.gz 124.0 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for nsjail-python 0.5.1
File Interpreter ABI Platform
nsjail_python-0.5.1-py3-none-any.whl Python 3 none any Details

Total release size: 151.0 kB

Release files / nsjail_python-0.5.1.tar.gz

Download URL nsjail_python-0.5.1.tar.gz
Size 124.0 kB
Tags Source
SHA-256 checksum
How to use checksums
1778c9c5f231159fff2b4f514121dc8c0f4eeea493384f1b762b29b7482c4ec6
BLAKE2b-256 checksum
How to use checksums
29b331adf007a1a30819e4f17bc60334d87a9f9f1c1e632f7349bacea584561b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Apr 12, 2026.

Transparency log

Release files / nsjail_python-0.5.1-py3-none-any.whl

Download URL nsjail_python-0.5.1-py3-none-any.whl
Size 27.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7be349a5e239aafa33b9b1a22ee687c04a18daf47585a1e44b267247266929ad
BLAKE2b-256 checksum
How to use checksums
6a7a4a27881f263024f327f2a66035fddf116b8292330a17aa11b0221acfe1a5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Apr 12, 2026.

Transparency log

Security for nsjail-python 0.5.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 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for nsjail_python-0.5.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 Apr 12, 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.

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