CoolFace
Apppublic

likhonsheikh/code-interpreter-sandbox

sourceHugging Facemitupdated 11mo agoView on Hugging Face
0likes
App README

๐Ÿš€ 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

FeatureCode Interpreter Sandboxe2b.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. 1.Use variables across executions: Variables persist within a session
  2. 2.Install packages first: Install required packages before using them
  3. 3.Save important outputs: Use file operations to save results
  4. 4.Check session info: Monitor your session status
  5. 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


Ready to code? Just start typing in the Code Executor tab! ๐Ÿš€