cohere-terrarium  by cohere-ai

Python sandbox for executing untrusted LLM-generated code

created 1 year ago
277 stars

Top 94.5% on sourcepulse

GitHubView on GitHub
Project Summary

Terrarium provides a secure, low-latency Python sandbox for executing untrusted LLM-generated code, targeting developers building data agents. It offers an economical solution for running Python scripts, generating visualizations, and processing data within a compartmentalized environment, with quick execution times and low hosting costs.

How It Works

Terrarium leverages Pyodide, a CPython distribution compiled to WebAssembly, to run Python code within a Node.js process. This approach isolates execution by providing a memory-only filesystem, preventing access to the host's memory or network. Each sandbox instance is completely recycled after every invocation, ensuring no state is carried over between calls.

Quick Start & Requirements

  • Install dependencies: npm install
  • Run locally: npm run dev
  • Execute code: curl -X POST -H "Content-Type: application/json" --url http://localhost:8080 --data-raw '{"code": "1 + 1"}'
  • Supported packages: numpy, pandas, matplotlib, sympy, etc. (see Pyodide documentation)
  • Deployment: Docker or GCP Cloud Run.

Highlighted Details

  • Fast execution: 900ms for PNG generation, 500ms for SVG.
  • Economical hosting: <$30/month on GCP Cloud Run (2GB mem, 1vCPU).
  • Native file support: Input/output files handled via base64 encoding.
  • plt.savefig() supported for Matplotlib; plt.show() is not.

Maintenance & Community

  • Developed by Cohere AI.
  • Deployment guidance provided for GCP Cloud Run, including health checks.

Licensing & Compatibility

  • No license specified in the README.
  • Compatibility for commercial use or closed-source linking is not explicitly stated.

Limitations & Caveats

Package installation, network access, and complex computations can be challenging. Pyodide may encounter "Maximum call stack size exceeded" errors with very high DPI settings or complex Pandas operations.

Health Check
Last commit

1 year ago

Responsiveness

Inactive

Pull Requests (30d)
0
Issues (30d)
0
Star History
22 stars in the last 90 days

Explore Similar Projects

Feedback? Help us improve.