Skip to main content
Python Sandbox module lets you run secure Python code directly in conversations, with persistent session state and access to Pyodide-compatible libraries. Key features:
  • Run Python code in an isolated WebAssembly environment with configurable permissions via Deno
  • Access Pyodide-compatible packages
  • Persist variables, imports, and function definitions across code blocks in the same conversation
  • Execute calculations, data analysis, and visualizations without leaving the chat
  • Skip setup entirely — runs out-of-the-box once Deno is installed on the server, no Python installation needed

Prerequisites

  • User role with conversation or agent edit access
  • Python Sandbox enabled in your chat or agent

How to Enable Python Sandbox

The default state of the Python Sandbox module — on or off — is defined in the project settings. If Python Sandbox is turned off by default, you can turn it on for your current conversation or agent.

For a Conversation

  1. Go to the conversation.
  2. Select + in the chat input toolbar.
  3. Select Modules → Python Sandbox in the list.
  4. Toggle Python Sandbox on.
Enable Python Sandbox in a Conversation Once enabled, you can execute Python code directly in that conversation.

For an Agent

  1. Select Agents.
  2. Select the agent to configure, or create a new agent.
  3. In the TOOLS section, find MODULES.
  4. Find Python Sandbox. Select Show all if you do not see it immediately.
  5. Toggle Python Sandbox on.
  6. Select Save.
All changes apply only to new conversations run by this agent. Existing conversations will not be affected. Enable Python Sandbox in Agent Configuration
For agents designed for data analysis, testing, or development tasks, enabling Python Sandbox significantly enhances their problem-solving capabilities and allows them to provide executable solutions.

How Python Sandbox Works

With Python Sandbox enabled, you can:
  • Execute multi-line Python scripts
  • Use Pyodide-compatible packages (NumPy, Pandas, Matplotlib, SciPy, scikit-learn, etc.)
  • Perform complex calculations and data transformations
  • Generate visualizations and charts (via matplotlib)
  • Maintain variables and state between executions in the same conversation
  • Handle errors gracefully and provide debugging information
  • Install additional packages available in the Pyodide ecosystem
Traditional Approach vs Python Sandbox

Execution Flow

When Python Sandbox is enabled, ELITEA handles code execution automatically:
  1. Code Generation: Assistant writes Python code to solve your request.
  2. Sandbox Invocation: Code is sent to the Pyodide sandbox environment via Deno subprocess.
  3. Isolated Execution: Code runs in WebAssembly with access to Pyodide packages.
  4. Result Capture: Output (print statements, return values, errors) is captured.
  5. Response Integration: Results are formatted and returned in the conversation.

Possible Use Cases

Data Analysis and Processing

  • Process datasets and calculate statistics
  • Transform data structures using NumPy and Pandas

Algorithm Testing and Validation

  • Test code snippets
  • Validate algorithms with comprehensive test cases
  • Prototype solutions before production implementation

Mathematical Computations

  • Perform complex calculations
  • Solve equations
  • Run numerical analysis and mathematical modeling

Quick Prototyping

  • Iterate rapidly on solutions without leaving the conversation
  • Skip local environment setup
  • Get instant feedback during development

Heavy Computational Tasks

When performing heavy computational tasks, keep in mind these limitations:
  • Timeouts: Very large datasets or computationally intensive operations may hit Deno timeout limits (default: 60 seconds). For production workloads with large-scale data processing, use dedicated Python environments.
  • Package availability: Some Python packages are not available in Pyodide. Check the Pyodide packages list before relying on specific libraries. C-extension packages may not be supported.
  • File system access: Limited file I/O capabilities due to WebAssembly sandbox restrictions. For tasks requiring extensive file operations or system-level access, consider alternative approaches.
  • Network operations: Network access is configurable via Deno permissions but may be restricted depending on server configuration. External API calls and web scraping may not work as expected.

Example Scenarios

User: I’m writing a function to validate email addresses. Can you help me test it with various inputs to make sure it works correctly?
Assistant: I’ll help you test your email validation function with a comprehensive set of test cases! Let me run various inputs through it to identify any edge cases.A Python Sandbox badge appears in the chat. Selecting it opens the executed code and its output in separate panes:
Output:
Great! Your improved email validation function passes all test cases. The enhancements you made successfully handle:
  • Consecutive dots (rejected)
  • Domain without TLD (rejected)
  • Proper multi-part domains (accepted)
  • Special characters in local part (accepted when appropriate)
Scenario: A data analyst needs to quickly analyze a dataset and calculate statistical metrics.User Request:
“I have sales data for the past 12 months: [45000, 52000, 48000, 61000, 58000, 67000, 72000, 68000, 75000, 81000, 79000, 88000]. Calculate mean, median, standard deviation, and identify the growth trend.”
Assistant Response:The assistant generates and executes Python code using NumPy to:
  • Calculate mean, median, and standard deviation
  • Compute month-over-month growth rates
  • Identify the overall trend
  • Present results in a formatted summary
Code Executed:
Python Sandbox enables instant analysis without switching tools or exporting data, with results returned directly in the conversation.
Scenario: A developer wants to test a binary search implementation with various edge cases.User Request:
“Test my binary search function with edge cases including empty arrays, single elements, duplicate values, and targets not in the array.”
Assistant Response:The assistant:
  • Generates comprehensive test cases covering all edge cases
  • Executes the algorithm with each test case
  • Validates correctness for each scenario
  • Reports results with detailed pass/fail status and execution details
Code Executed:
Python Sandbox provides immediate feedback on algorithm behavior and comprehensive edge case validation.
Scenario: A student needs to solve quadratic equations and understand the mathematical properties.User Request:
“Solve the quadratic equation 2x² - 8x + 6 = 0 and explain the solutions.”
Assistant Response:Using Python Sandbox with mathematical operations:
  • Calculates discriminant to determine solution types
  • Computes exact solutions using the quadratic formula
  • Verifies solutions by substitution
  • Explains the mathematical interpretation
Code Executed:
Python Sandbox brings mathematical concepts to life with executable code and instant verification.

Best Practices

Pyodide supports many popular Python packages including NumPy, Pandas, Matplotlib, SciPy and scikit-learn. These packages are precompiled for WebAssembly and work seamlessly in the sandbox environment.Check the Pyodide packages list for available packages.
Ask ELITEA to break complex analysis into logical steps. Each code block can build on previous results since the sandbox maintains state within a conversation. This makes it easier to understand the process and identify issues.
When working with conversation attachments (CSV, Excel files), enable both Python Sandbox and Data Analysis modules. Python Sandbox provides the execution environment, while Data Analysis can help with file parsing and data structure handling.
Python Sandbox works seamlessly alongside Swarm Mode. In multi-agent setups, individual child agents can each have Python Sandbox enabled, allowing them to perform independent code execution tasks within the shared conversation context.
While Python Sandbox is secure and isolated, reviewing the code the assistant plans to execute helps you understand the approach and learn from the implementation. This is especially valuable for educational use cases.
When requesting data analysis or processing, include sample data in your message or describe the data format clearly. This helps the assistant generate more accurate and relevant code tailored to your specific use case.
When asking the assistant to work with data structures or algorithms, use clear descriptions and specify expected behavior. This helps generate more readable and maintainable code with appropriate variable names and comments.

Troubleshooting

Possible Causes:
  • Python Sandbox not enabled in chat or agent configuration
  • Deno not installed on the server
  • Backend service unavailable or crashed
Solution:
  1. Verify Python Sandbox is enabled in MODULES for the chat or agent
  2. Check that the success notification appeared when enabling the tool
  3. Contact system administrator to verify Deno installation on the server
  4. Try disabling and re-enabling Python Sandbox to reset the connection
  5. Refresh the page and start a new chat to reset state
  6. Check server logs for Deno-related errors
Possible Causes:
  • Package not available in the Pyodide ecosystem
  • Package not preloaded in the sandbox environment
  • Typo in package name
Solution:
  1. Verify the package is listed in the Pyodide packages list
  2. Use alternative packages that are Pyodide-compatible
  3. Check the error message for suggestions on alternative packages
  4. Some pure Python packages may need to be loaded dynamically
Possible Causes:
  • Long-running computations exceeding the timeout limit
  • Infinite loops in the code
  • Large dataset processing taking too long
Solution:
  1. Break large computations into smaller chunks that execute faster
  2. Optimize algorithms to reduce time complexity
  3. Use iterative processing for large datasets
  4. Review code for potential infinite loops or performance bottlenecks
  5. Consider using a local Python environment for heavy computations
Possible Causes:
  • Conversation reset or page refresh
  • Backend session expiration
  • An error in a previous code execution corrupted the session state
Solution:
  1. Re-run initialization code to redefine variables and imports
  2. Avoid page refreshes during stateful work sessions
  3. Check for errors in previous executions that may have corrupted the state
  4. Use explicit variable definitions in each code block for critical values
  5. Start a new conversation if the session state is corrupted
Possible Causes:
  • Network access not allowed by Deno permissions
  • Firewall blocking outbound connections from the sandbox
  • Using the requests library instead of httpx.AsyncClient
Solution:
  1. Ensure network access is configured in the sandbox settings (allow_net=True)
  2. Use httpx.AsyncClient for HTTP requests instead of the requests library
  3. Contact the administrator to check the Deno network permission configuration
  4. Check if specific domains need to be whitelisted in the Deno settings