Skip to content

AJAmit17/E2B-Streamlit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

💻 Code Execution Chat

A Streamlit-based chat application that executes Python and Node.js code in secure E2B sandboxes using OpenAI's function calling capabilities.

Python Streamlit License

✨ Features

  • 🤖 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

🚀 Quick Start

Prerequisites

  • Python 3.9+
  • OpenAI API key
  • E2B API key (get one at e2b.dev)

Installation

  1. Clone the repository

    git clone https://github.com/yourusername/code-execution-chat.git
    cd code-execution-chat
  2. Create a virtual environment

    python -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
  3. Install dependencies

    pip install -r requirements.txt
  4. Set up environment variables

    cp .env.example .env

    Edit .env and add your API keys:

    OPENAI_API_KEY=your_openai_api_key_here
    E2B_API_KEY=your_e2b_api_key_here
    
  5. Run the application

    streamlit run app.py

📁 Project Structure

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

🎯 Usage Examples

Python - Plot a Sine Wave

"Create a Python app that plots a sine wave"

Node.js - Express Server

"Build an Express server with a hello world endpoint and test it with axios"

Data Analysis

"Write a Python script to generate sample sales data and create a bar chart"

🔧 Configuration

Environment Variables

Variable Description Required
OPENAI_API_KEY Your OpenAI API key Yes
E2B_API_KEY Your E2B sandbox API key Yes

Available Models

  • GPT-4o (default)
  • GPT-4o-mini
  • GPT-4-turbo
  • GPT-3.5-turbo

🛠️ Supported Technologies

Python

  • Any pip package (auto-installed)
  • Matplotlib, NumPy, Pandas, etc.
  • Data visualization libraries

Node.js/JavaScript

  • ES Modules support
  • Top-level await
  • npm packages (auto-installed)
  • Express.js, Axios, etc.

🔒 Security

  • 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

📝 License

MIT License - see LICENSE for details.

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

🙏 Acknowledgments

  • OpenAI for GPT models and function calling
  • E2B for secure code execution sandboxes
  • Streamlit for the amazing web framework

About

A code interpreter application built with E2B (Execute to Backend) and Streamlit, enabling secure sandboxed code execution in the browser. Execute Python code safely with an interactive UI powered by Streamlit.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages