likhonsheikh's picture
Initial commit: Advanced Code Interpreter Sandbox
6b36488 verified
---
title: Advanced Code Interpreter Sandbox
emoji: πŸš€
colorFrom: blue
colorTo: purple
sdk: docker
sdk_version: "24.1.2"
app_file: app.py
pinned: false
license: mit
hardware: t4-small
---
# πŸš€ Advanced Code Interpreter Sandbox
A powerful, feature-rich code execution environment on HuggingFace Spaces that rivals e2b.dev! This sandbox provides a comprehensive Python development environment with advanced capabilities.
## ✨ Features
### πŸ” Secure Code Execution
- Safe, sandboxed Python code execution
- Timeout protection (10s default)
- Memory limit controls
- Syntax error handling
- Exception capture and display
### πŸ“ File System Support
- Upload files directly to the workspace
- Download results and outputs
- Multi-file management
- Real-time file operations (read, delete, list)
- Temporary file storage with session isolation
### πŸ“¦ Package Management
- On-the-fly package installation via pip
- Support for popular data science libraries
- Package version management
- Quick install of common packages (numpy, pandas, matplotlib, plotly, etc.)
- Pre-installed essential packages
### πŸ“Š Data Visualization
- Built-in support for:
- **Matplotlib** - Static plots and charts
- **Plotly** - Interactive visualizations
- **Seaborn** - Statistical data visualization
- **Bokeh** - Interactive plots
- **Altair** - Declarative visualization
- **Pillow** - Image processing
### πŸ’Ύ Session Persistence
- Maintains state throughout session
- File persistence
- Package installation history
- Session information tracking
- Uptime monitoring
### πŸ”„ Real-time Output
- Streamed stdout/stderr capture
- Live code execution feedback
- Error highlighting
- Output mode selection (stdout, stderr, or both)
### πŸ“ Multi-file Support
- Create and manage multiple files
- File editor interface
- Switch between files easily
- Automatic file detection
- File metadata tracking
### 🎨 Superior UX
- Clean, modern Gradio interface
- Dark theme support
- Intuitive tabbed interface
- Responsive design
- Syntax highlighting in code editor
- Progress indicators
## πŸš€ Getting Started
### 1. Run Your Code
```python
# Write Python code in the editor
print("Hello, World!")
# Import any installed package
import numpy as np
arr = np.array([1, 2, 3, 4, 5])
print(f"Array: {arr}")
print(f"Mean: {np.mean(arr)}")
```
### 2. Install Packages
- Go to "Package Manager" tab
- Enter package names (comma-separated)
- Click "Install"
- Example: `numpy, pandas, matplotlib, plotly`
### 3. Upload Files
- Go to "File Manager" tab
- Upload files using the file picker
- Files are stored in your workspace
- Access files directly in your code
### 4. Data Visualization Example
```python
import matplotlib.pyplot as plt
import numpy as np
# Generate data
x = np.linspace(0, 10, 100)
y = np.sin(x)
# Create plot
plt.figure(figsize=(10, 6))
plt.plot(x, y, 'b-', label='sin(x)')
plt.xlabel('x')
plt.ylabel('y')
plt.title('Sine Wave')
plt.legend()
plt.grid(True)
plt.show()
```
## πŸ“š Pre-installed Libraries
The following packages are pre-installed and ready to use:
- NumPy
- Pandas
- Matplotlib
- Plotly
- Seaborn
- SciPy
- Scikit-learn
- Pillow
- Requests
- BeautifulSoup4
- NetworkX
- SymPy
## πŸ”§ Available Packages
You can install additional packages using the Package Manager. Popular options:
- `tensorflow` - Machine learning
- `torch` - Deep learning
- `transformers` - Hugging Face transformers
- `streamlit` - Web app framework
- `dash` - Interactive dashboards
- `openai` - OpenAI API client
- `langchain` - LLM application framework
- `wordcloud` - Text visualization
- `geopandas` - Geospatial analysis
- ` sqlalchemy` - Database ORM
## 🎯 Use Cases
### Data Analysis
```python
import pandas as pd
import matplotlib.pyplot as plt
# Load and analyze data
df = pd.read_csv('your_data.csv')
print(df.head())
df.describe().plot()
plt.show()
```
### Machine Learning
```python
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import train_test_split
# Train a model
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
model = RandomForestClassifier()
model.fit(X_train, y_train)
```
### Web Scraping
```python
import requests
from bs4 import BeautifulSoup
# Scrape a webpage
url = "https://example.com"
response = requests.get(url)
soup = BeautifulSoup(response.content, 'html.parser')
print(soup.title)
```
### API Integration
```python
import requests
import json
# Call an API
response = requests.get('https://api.github.com/users/octocat')
data = response.json()
print(json.dumps(data, indent=2))
```
## ⚠️ Security Notes
- Code runs in a secure sandbox environment
- No network access to external resources (except for package installation and explicit API calls)
- Files are isolated per session
- Execution timeouts prevent infinite loops
- Maximum memory usage is limited
## πŸ†š Compared to e2b.dev
| Feature | Code Interpreter Sandbox | e2b.dev |
|---------|-------------------------|---------|
| Package Installation | βœ… Yes | βœ… Yes |
| File Upload/Download | βœ… Yes | βœ… Yes |
| Data Visualization | βœ… Yes | βœ… Yes |
| Session Persistence | βœ… Yes | βœ… Yes |
| Real-time Output | βœ… Yes | βœ… Yes |
| Multi-file Support | βœ… Yes | βœ… Yes |
| Cost | πŸ†“ Free on Spaces | πŸ’° Paid |
| Custom Environment | 🐳 Docker-based | 🐳 Docker-based |
| Pre-installed Libraries | πŸ“¦ 20+ packages | πŸ“¦ Limited |
| GitHub Integration | 🟑 Manual | βœ… Automatic |
## 🎨 Interface Overview
### Code Executor Tab
- Write and execute Python code
- Choose output mode (stdout, stderr, or both)
- Real-time execution feedback
- Syntax highlighting
### File Manager Tab
- Upload files to workspace
- View and manage all files
- Read file contents
- Delete unwanted files
### Package Manager Tab
- Install packages on-the-fly
- View installed packages
- Batch installation support
### Session Info Tab
- View session details
- Monitor uptime
- Track installed packages
- Workspace information
## πŸš€ Deployment
This application is designed for HuggingFace Spaces and includes:
- Optimized `requirements.txt`
- Pre-configured dependencies
- Docker support
- GPU acceleration ready
## πŸ“ Tips & Tricks
1. **Use variables across executions**: Variables persist within a session
2. **Install packages first**: Install required packages before using them
3. **Save important outputs**: Use file operations to save results
4. **Check session info**: Monitor your session status
5. **Explore the interface**: Each tab provides different functionality
## 🀝 Contributing
Contributions are welcome! Areas for improvement:
- Additional language support
- Enhanced visualization options
- More pre-installed packages
- Improved error handling
- Better performance optimization
## πŸ“„ License
This project is open source and available under the MIT License.
## πŸ™ Acknowledgments
- Built with [Gradio](https://gradio.app/)
- Powered by [HuggingFace Spaces](https://huggingface.co/spaces)
- Inspired by [e2b.dev](https://e2b.dev/)
---
**Ready to code?** Just start typing in the Code Executor tab! πŸš€