File size: 7,147 Bytes
6b36488
 
 
 
 
 
 
 
 
 
 
 
 
523f6c3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a407e7c
 
523f6c3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
---
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! πŸš€