A sandboxed Code runner
Project description
LineRun
LineRun is an isolated Python execution environment ("sandbox") tailored specifically for autonomous AI agents. It provides a clean, path-traversal-protected interface for writing code, managing dependencies via virtual environments, and executing Python scripts safely.
Features
- Virtual Environment Isolation: Automatically creates a dedicated
venvfor each runner instance. - Path Traversal Protection: Enforces strict boundaries to ensure agents cannot read, edit, or execute files outside the designated sandbox directory.
- AI-Friendly File I/O: Provides methods specifically designed to reduce LLM token usage and formatting hallucinations, including full-file overwrites and exact-string replacements.
- Dependency Management: Native API for pip installing and managing external modules within the sandbox.
- NixOS Compatibility: Automatically detects NixOS and wraps execution in a
nix-shellconfigured to properly link dynamic C/C++ libraries (likelibstdc++, OpenGL, X11) when installing binary wheels from PyPI.
Installation
LineRun is built using standard Python libraries and can be packaged via PyPI.
git clone
cd LineRun
pip install -e .
If you intend to run this in a production environment with untrusted AI code, it is highly recommended to install and run LineRun inside an isolated Docker container. Directory separation alone does not prevent malicious OS-level system calls or network access.
Quick Start
from linerun.main import Code_Runner
# 1. Initialize the sandbox
# This automatically creates the venv
runner = Code_Runner(Path="./my_sandbox", Venv_Path="./my_venv")
# 2. Add dependencies
runner.Add_Module("requests")
# 3. Write code
script = '''
import requests
resp = requests.get("https://api.github.com")
print("Status Code:", resp.status_code)
'''
runner.Write_File("fetch.py", script)
# 4. Execute the code
output = runner.Run_Code("fetch.py")
print("Agent Output:", output)
API Reference
Initialization
Code_Runner(Path, Venv_Path): Creates a new sandboxed runner. Will throw an error ifPathis not empty. Automatically scaffolds the Python virtual environment.
File Operations
Write_File(Name, Content): Overwrites (or creates) a file with the exact content provided.Replace_In_File(Name, TargetContent, ReplacementContent): Finds the first exact match ofTargetContentand replaces it. Ideal for surgical patches. Throws an error if the match is not exact.Read_File(Name): Returns the string contents of a file.Add_File(Name): Creates an empty file.Delete_File(Name): Deletes a file.All_files(regex=None): Returns a list of all files relative to the sandbox path. Supports optional regex filtering.
Dependency Management
Add_Module(Name): Uses pip to install a package into the virtual environment.Remove_Module(Name): Uninstalls a package.List_Modules(): Lists all installed pip packages.
Execution
Run_Code(Name): Executes a file using the virtual environment's Python binary. Captures and returns standard output.
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 linerun-0.1.0.tar.gz.
File metadata
- Download URL: linerun-0.1.0.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
86ee9231e6c341330887e1ba391e83f979be2218cd67fd661914bbcca03c45d6
|
|
| MD5 |
9f0eb1f1c22304d5bd558e4f3ceddf4d
|
|
| BLAKE2b-256 |
06d8bc9b9d8114d957f947de0690edebad6c7d1390c76951664a86e32b183f9d
|
Provenance
The following attestation bundles were made for linerun-0.1.0.tar.gz:
Publisher:
python-publish.yml on Octahedron-apple/LineRun
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
linerun-0.1.0.tar.gz -
Subject digest:
86ee9231e6c341330887e1ba391e83f979be2218cd67fd661914bbcca03c45d6 - Sigstore transparency entry: 1789252924
- Sigstore integration time:
-
Permalink:
Octahedron-apple/LineRun@105bbb76d5b7d98a5446fcb85842180bb72fd9a1 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/Octahedron-apple
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@105bbb76d5b7d98a5446fcb85842180bb72fd9a1 -
Trigger Event:
release
-
Statement type:
File details
Details for the file linerun-0.1.0-py3-none-any.whl.
File metadata
- Download URL: linerun-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
171598a7ec58ef4203288955979ff7198f1b5b0d63f493604ba9c7c404239e52
|
|
| MD5 |
0ef574d45a42cf870942ebe2bc6d89e6
|
|
| BLAKE2b-256 |
23c4c2f57846debcf2911ad46740543d5efd77d51e1052dc59079ab4229a8214
|
Provenance
The following attestation bundles were made for linerun-0.1.0-py3-none-any.whl:
Publisher:
python-publish.yml on Octahedron-apple/LineRun
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
linerun-0.1.0-py3-none-any.whl -
Subject digest:
171598a7ec58ef4203288955979ff7198f1b5b0d63f493604ba9c7c404239e52 - Sigstore transparency entry: 1789252956
- Sigstore integration time:
-
Permalink:
Octahedron-apple/LineRun@105bbb76d5b7d98a5446fcb85842180bb72fd9a1 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/Octahedron-apple
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@105bbb76d5b7d98a5446fcb85842180bb72fd9a1 -
Trigger Event:
release
-
Statement type: