A Streamlit-based chat application that executes Python and Node.js code in secure E2B sandboxes using OpenAI's function calling capabilities.
- 🤖 AI-Powered Code Generation - Uses OpenAI GPT-4 to understand requests and generate code
- 🐍 Python Execution - Run Python code with automatic dependency installation
- 🟢 Node.js/JavaScript - Execute JavaScript with npm package support
- 📊 Visualization Support - Display matplotlib plots, charts, and images inline
- 🔒 Secure Sandboxes - Code runs in isolated E2B cloud sandboxes
- 💬 Chat Interface - Natural conversation flow with code execution
- Python 3.9+
- OpenAI API key
- E2B API key (get one at e2b.dev)
-
Clone the repository
git clone https://github.com/yourusername/code-execution-chat.git cd code-execution-chat -
Create a virtual environment
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies
pip install -r requirements.txt
-
Set up environment variables
cp .env.example .env
Edit
.envand add your API keys:OPENAI_API_KEY=your_openai_api_key_here E2B_API_KEY=your_e2b_api_key_here -
Run the application
streamlit run app.py
code-execution-chat/
├── app.py # Main Streamlit application
├── src/
│ ├── __init__.py
│ ├── config.py # Configuration and constants
│ ├── sandbox.py # E2B sandbox execution logic
│ ├── chat.py # OpenAI chat handling
│ └── ui.py # Streamlit UI components
├── requirements.txt # Python dependencies
├── .env.example # Example environment variables
├── .gitignore
└── README.md
"Create a Python app that plots a sine wave"
"Build an Express server with a hello world endpoint and test it with axios"
"Write a Python script to generate sample sales data and create a bar chart"
| Variable | Description | Required |
|---|---|---|
OPENAI_API_KEY |
Your OpenAI API key | Yes |
E2B_API_KEY |
Your E2B sandbox API key | Yes |
- GPT-4o (default)
- GPT-4o-mini
- GPT-4-turbo
- GPT-3.5-turbo
- Any pip package (auto-installed)
- Matplotlib, NumPy, Pandas, etc.
- Data visualization libraries
- ES Modules support
- Top-level await
- npm packages (auto-installed)
- Express.js, Axios, etc.
- All code executes in isolated E2B cloud sandboxes
- Sandboxes are automatically destroyed after execution
- No persistent storage between executions
- API keys are never exposed to executed code
MIT License - see LICENSE for details.
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request