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
-
Install the
runscbinary:# 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
-
Register
runscwith 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.confor/etc/containers/containers.conf:[engine.runtimes] runsc = ["/usr/local/bin/runsc"]
-
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
21d93d61e178bbbf11b5d8f5a165547df8222e661c12bc9c664f7e4760a36cbf
|
|
| MD5 |
db0f2f5c984eb19e25b74de4d2f555fc
|
|
| BLAKE2b-256 |
baa9c3e23e094961e92b7081a935f2e411fb7eff01f79113d589ccb6c72666ea
|
Provenance
The following attestation bundles were made for backyard-0.2.0.tar.gz:
Publisher:
publish.yml on rparkr/backyard
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
backyard-0.2.0.tar.gz -
Subject digest:
21d93d61e178bbbf11b5d8f5a165547df8222e661c12bc9c664f7e4760a36cbf - Sigstore transparency entry: 2194659343
- Sigstore integration time:
-
Permalink:
rparkr/backyard@9f390df26d0cdb0680c88d1efa23c69de80b0868 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/rparkr
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9f390df26d0cdb0680c88d1efa23c69de80b0868 -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5d35a5cbe56aced24692e06e1e94ec159a8926a4df027b8de72f02e47375bf7c
|
|
| MD5 |
c8bc540ead89a8974d6a2018af0b1b46
|
|
| BLAKE2b-256 |
8eeda76fc36237f4b04851a52499dbc441625e4710af45f9f52e6ba8902dfd6d
|
Provenance
The following attestation bundles were made for backyard-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on rparkr/backyard
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
backyard-0.2.0-py3-none-any.whl -
Subject digest:
5d35a5cbe56aced24692e06e1e94ec159a8926a4df027b8de72f02e47375bf7c - Sigstore transparency entry: 2194659346
- Sigstore integration time:
-
Permalink:
rparkr/backyard@9f390df26d0cdb0680c88d1efa23c69de80b0868 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/rparkr
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9f390df26d0cdb0680c88d1efa23c69de80b0868 -
Trigger Event:
release
-
Statement type: