Skip to main content

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 venv for 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-shell configured to properly link dynamic C/C++ libraries (like libstdc++, 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 if Path is 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 of TargetContent and 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


Download files

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

Source Distribution

linerun-0.1.0.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

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

linerun-0.1.0-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

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

Hashes for linerun-0.1.0.tar.gz
Algorithm Hash digest
SHA256 86ee9231e6c341330887e1ba391e83f979be2218cd67fd661914bbcca03c45d6
MD5 9f0eb1f1c22304d5bd558e4f3ceddf4d
BLAKE2b-256 06d8bc9b9d8114d957f947de0690edebad6c7d1390c76951664a86e32b183f9d

See more details on using hashes here.

Provenance

The following attestation bundles were made for linerun-0.1.0.tar.gz:

Publisher: python-publish.yml on Octahedron-apple/LineRun

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

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

Hashes for linerun-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 171598a7ec58ef4203288955979ff7198f1b5b0d63f493604ba9c7c404239e52
MD5 0ef574d45a42cf870942ebe2bc6d89e6
BLAKE2b-256 23c4c2f57846debcf2911ad46740543d5efd77d51e1052dc59079ab4229a8214

See more details on using hashes here.

Provenance

The following attestation bundles were made for linerun-0.1.0-py3-none-any.whl:

Publisher: python-publish.yml on Octahedron-apple/LineRun

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