|
|
--- |
|
|
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! π |
|
|
|