Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Python Executor #6

Merged
merged 2 commits into from
Mar 9, 2025
Merged

Add Python Executor #6

merged 2 commits into from
Mar 9, 2025

Conversation

danilowhk
Copy link
Member

Overview

This PR adds a secure Python code execution capability to the FLASH toolkit, implementing a sandboxed Python environment that enhances the toolkit's computational abilities. Using Pyodide (Python compiled to WebAssembly), this tool enables AI agents to safely execute Python code for data analysis, visualization, and computation while maintaining strong security boundaries.

New Features

Python Code Execution Tool

Core Functionality:

  • Securely execute arbitrary Python code in a WebAssembly sandbox
  • Install Python packages on-demand for extended functionality
  • Generate and return matplotlib visualizations
  • Capture stdout, stderr, and execution results

Security Features:

  • Complete isolation from the host system via WebAssembly sandbox
  • Configurable execution timeouts to prevent infinite loops
  • Memory usage limits to prevent resource exhaustion
  • No file system or network access by default

Execution Options:

  • Timeout controls (default: 5 seconds)
  • Memory limit settings (default: 512MB)
  • Package installation for extended functionality
  • Plot generation and capture capabilities

Implementation Details

  • Uses Pyodide to run Python in a WebAssembly sandbox
  • Implements Promise.race pattern for timeout enforcement
  • Provides consistent, well-formatted output with markdown sections
  • Dynamically imports dependencies to support various runtime environments

Testing

  • Unit tests for code execution
  • Error handling verification
  • Memory and timeout constraint testing
  • Package installation tests

This powerful but secure Python execution environment opens up new possibilities for computational and analytical tasks within the FLASH framework.

@Arthur-Jacobina Arthur-Jacobina merged commit e6362b2 into main Mar 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants