Skip to main content

A logo with the word 'backyard' and an drawing of a sandbox with a shovel in it

--> Documentation

Backyard

Fast Python sandbox for AI agent harnesses.

backyard supports safe and transparent execution of Python code using either:

  • Pydantic-Monty: an ultra-fast, minimal Python interpreter written in Rust
  • A container (Docker or Podman) with full-featured Python support

Getting started

Installation

Using uv (recommended):

uv add backyard

Or, with pip:

pip install backyard

Python API

from backyard import Sandbox

sandbox = Sandbox()

code = """
print("hello from the sandbox! 🏖🏰")
"""

result = sandbox.run(code)

print(result.stdout)

TUI

backyard comes with a notebook-like Text-based User Inferface (TUI) for trying out the sandboxes in your terminal. It requires the tui extra:

uv add "backyard[tui]"
uv run backyard

# Or, if you've activated the .venv already, you can run:
# backyard

Here's an example of the built-in TUI for accessing the sandboxes in a notebook-like environment.

It uses the Monty sandbox by default and transparently switches to a container-backed sandbox when executing code that requires third-party Python libraries or network access.

TUI demo Demo recorded with asciinema.

Security

Both sandbox backends provide strong security measures for running agent-generated code: read-only file mounting, resource constraints (memory, CPU usage, timeouts), and network restrictions.

For an added layer of security for container-based sandboxes, backyard supports the gVisor container runtime.

gVisor (runsc) sandboxing

For maximum isolation when running untrusted code, backyard automatically detects and uses gVisor (runsc) as the container runtime if it is registered with your container engine. gVisor provides an additional kernel-level security boundary between the sandboxed code and the host system.

If gVisor is not detected, backyard falls back to the default runc runtime and logs a warning.

Installing gVisor

Click to see instructions
  1. Install the runsc binary:

    # Ubuntu / Debian
    sudo apt-get install runsc
    
    # Or download the latest release
    wget https://storage.googleapis.com/gvisor/releases/release/latest/runsc
    sudo mv runsc /usr/local/bin/runsc
    sudo chmod +x /usr/local/bin/runsc
    
  2. Register runsc with your container engine by editing the daemon configuration:

    Docker — add to /etc/docker/daemon.json:

    {
        "runtimes": {
            "runsc": {
                "path": "/usr/local/bin/runsc"
            }
        }
    }
    

    Podman — add to ~/.config/containers/containers.conf or /etc/containers/containers.conf:

    [engine.runtimes]
    runsc = ["/usr/local/bin/runsc"]
    
  3. Restart the container engine:

    # Docker
    sudo systemctl restart docker
    
    # Podman (no daemon, but verify the config is picked up)
    podman info --format '{{json .Host.OCIRuntimes}}'
    

Once configured, backyard will automatically detect and use gVisor for all container sandboxes, providing an additional kernel-level security boundary.

FAQ

Why did you create this?

To power the code execution tool for an AI coding agent harness I'm developing.

Originally, I built the dual-engine sandbox for fine-tuning large language models using Reinforcement Learning from Verifiable Rewards (RLVR) with Group Relative Policy Optimization (GRPO). The sandbox provided an environment to safely execute parallel batches of model-generated code, computing rewards for training the model.

I modified and expanded the sandbox capabilities for use in the breeze coding agent harness I am building.

To adapt the sandbox to the needs of AI agents, I replaced the stateless, parallel execution approach with a stateful system that enables agents to execute code interactively, like a Python notebook or advanced REPL.

Where does the name backyard come from?

The term sandbox refers to a controlled environment where untrusted code can be run safely.

In the physical world, a sandbox is a place where children explore and imagine as they create and shape the world around them. 🏖🏰

Where are sandboxes placed? In the backyard.

License

This project is distributed under the MIT license.

Acknowledgements

A big thank you to the following teams for their work that makes this project possible:

  • The Pydantic team for creating Monty, the Rust-based Python interpreter that powers the ultra-fast default sandbox in backyard.
  • The Podman and Docker teams for building container runtimes that power the full-featured sandbox.
  • The Astral team for developing amazing tooling: the uv package manager (used in the full-featured sandbox), the ruff linter, and the ty type checker.
  • Will McGugan and contributors to Textual, the TUI framework that powers backyard's notebook-like TUI.
  • The Zensical team for the static site generator that powers backyard's documentation site.
  • Google's Gemini team for Gemini 3.6 Flash and the Nano Banana image-generation model, which I used to design the logo.
  • Scofield Eric for creating vectorize-image, which I used to convert the logo into SVG format
  • The marimo team for maintaining the list of import-to-PyPI package names used in backyard for automatic dependency installation

Metadata

Release files for backyard 0.3.0

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

Source distribution (sdist)

Source distribution for backyard 0.3.0
File Size Uploaded
backyard-0.3.0.tar.gz 66.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for backyard 0.3.0
File Interpreter ABI Platform
backyard-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 146.9 kB

Release files / backyard-0.3.0.tar.gz

Download URL backyard-0.3.0.tar.gz
Size 66.8 kB
Tags Source
SHA-256 checksum
How to use checksums
749f62ddce40a022675c786ab0e69209d151323431e720304eac45bd89d019ad
BLAKE2b-256 checksum
How to use checksums
21f885382a4f04028010998ffbf293b26eb651a4a4c247751ad6306d8df41315
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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 Aug 2, 2026.

Transparency log

Release files / backyard-0.3.0-py3-none-any.whl

Download URL backyard-0.3.0-py3-none-any.whl
Size 80.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
abcf671c467052a8160ff0205973c7b690df6a55f41cb64cdc7b5300d570112a
BLAKE2b-256 checksum
How to use checksums
9f17fa330396aba27e6e3c3da03da00ba48c9c5386ca016392e69ec159dbce98
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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 Aug 2, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.0

2 release files

0.1.0

2 release files

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