KEMBAR78
GitHub - Josh-XT/SafeExecute: Safe Python Code Execution Environment for Language Models
Skip to content

Josh-XT/SafeExecute

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SafeExecute

GitHub PayPal Ko-Fi

This module provides a safe way to execute Python code and shell commands in a sandboxed environment. It uses Bubblewrap for lightweight sandboxing without requiring Docker socket access, making it compatible with cloud platforms like Digital Ocean, AWS ECS, Google Cloud Run, and Azure Container Instances. Docker is available as an optional fallback when Bubblewrap is not available.

The container comes preloaded with the following packages:

  • numpy
  • matplotlib
  • seaborn
  • scikit-learn
  • yfinance
  • scipy
  • statsmodels
  • sympy
  • bokeh
  • plotly
  • dash
  • networkx
  • pyvis
  • pandas
  • agixtsdk

Installation

# Basic installation (Bubblewrap sandboxing)
pip install safeexecute

# With optional Docker fallback support
pip install safeexecute[docker]

System Requirements

For full sandboxing functionality, install Bubblewrap:

# Ubuntu/Debian
apt-get install bubblewrap

# Fedora/RHEL  
dnf install bubblewrap

# Alpine Linux
apk add bubblewrap

Note: If Bubblewrap is not available, SafeExecute will automatically fall back to Docker (if docker package is installed) or execute code with limited isolation.

Features

  • No Docker Socket Required - Works on cloud platforms without Docker-in-Docker support
  • Bubblewrap Sandboxing - Lightweight, secure isolation without containers
  • Shell Command Support - Execute bash commands with state persistence
  • Workspace Persistence - Files persist between commands in conversation
  • Directory Navigation - cd commands work with state preservation
  • Multi-Conversation Isolation - Each conversation gets its own workspace
  • Automatic Fallback - Uses Docker when available if Bubblewrap is not installed

Usage

You can pass an entire message from a langauge model into the code field and it will parse out any Python code blocks and execute them. If anywhere in the code says pip install <package>, it will install the package in the container before executing the code.

from safeexecute import execute_python_code, execute_shell_command

# Execute Python code
code = "print('Hello, World!')"
result = execute_python_code(code=code)
print(result)

# Execute shell commands (new feature!)
result = execute_shell_command("echo 'Hello from shell!'")
print(result)

# Commands maintain state (directory changes persist)
execute_shell_command("mkdir my_project")
execute_shell_command("cd my_project")
result = execute_shell_command("pwd")  # Will show /workspace/my_project

About

Safe Python Code Execution Environment for Language Models

Resources

License

Stars

Watchers

Forks

Sponsor this project

  •  

Packages