Skip to main content

Fast Python sandboxes for AI agents.

Project description

Backyard

Fast Python Sandbox for AI agent harnesses.

backyard supports transparent execution of Python code using either:

  • Pydantic-Monty: an ultra-fast, minimal Python interpreter
  • a container engine (Docker or Podman): full-featured Python support

Getting started

Installation

Using uv (recommended):

uv add backyard

Or, with pip:

pip install backyard

Python API

from pprint import pprint

from backyard import Sandbox

sandbox = Sandbox()

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

result = sandbox.run(code)

pprint(result)

Security

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

  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?

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 model-generated code and generate rewards for training the model.

I then expanded the sandbox capabilities for use in the my-ai coding agent harness I am building.

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 does one place a sandbox? In the backyard.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

backyard-0.2.0.tar.gz (61.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

backyard-0.2.0-py3-none-any.whl (74.6 kB view details)

Uploaded Python 3

File details

Details for the file backyard-0.2.0.tar.gz.

File metadata

  • Download URL: backyard-0.2.0.tar.gz
  • Upload date:
  • Size: 61.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for backyard-0.2.0.tar.gz
Algorithm Hash digest
SHA256 21d93d61e178bbbf11b5d8f5a165547df8222e661c12bc9c664f7e4760a36cbf
MD5 db0f2f5c984eb19e25b74de4d2f555fc
BLAKE2b-256 baa9c3e23e094961e92b7081a935f2e411fb7eff01f79113d589ccb6c72666ea

See more details on using hashes here.

Provenance

The following attestation bundles were made for backyard-0.2.0.tar.gz:

Publisher: publish.yml on rparkr/backyard

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file backyard-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: backyard-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 74.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for backyard-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5d35a5cbe56aced24692e06e1e94ec159a8926a4df027b8de72f02e47375bf7c
MD5 c8bc540ead89a8974d6a2018af0b1b46
BLAKE2b-256 8eeda76fc36237f4b04851a52499dbc441625e4710af45f9f52e6ba8902dfd6d

See more details on using hashes here.

Provenance

The following attestation bundles were made for backyard-0.2.0-py3-none-any.whl:

Publisher: publish.yml on rparkr/backyard

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page