Spaces:
Build error
Build error
File size: 6,876 Bytes
6f07e2b |
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 |
# Ubuntu Sandbox Environment - Deployment Guide
## Quick Start
### 1. Create a New HuggingFace Space
1. Go to [huggingface.co/spaces](https://huggingface.co/spaces)
2. Click "Create new Space"
3. Choose **Docker** as the SDK
4. Name your space (e.g., `ubuntu-sandbox`)
5. Set license (e.g., MIT)
6. Choose hardware (CPU is sufficient, GPU optional)
### 2. Upload Files
Upload the following files to your new space:
```
π Your Space Repository
βββ app.py # Main application
βββ requirements.txt # Python dependencies
βββ Dockerfile # Container configuration
βββ config.yaml # Environment settings
βββ README.md # Documentation
βββ USAGE_GUIDE.md # This file
```
### 3. Deploy
1. After uploading, HuggingFace will automatically build your space
2. The build process takes 5-10 minutes
3. Once built, your space will be available at:
`https://your-username-ubuntu-sandbox.hf.space`
## Configuration
### Environment Variables
You can set these environment variables in your space settings:
| Variable | Default | Description |
|----------|---------|-------------|
| `INSTALL_TOOLS` | `true` | Install additional development tools |
| `MAX_OUTPUT_LINES` | `1000` | Maximum lines in terminal output |
| `COMMAND_TIMEOUT` | `30` | Timeout for command execution (seconds) |
| `AI_FRIENDLY_MODE` | `true` | Enable AI-specific features |
### Hardware Requirements
- **Minimum**: 2GB RAM, 1 CPU core
- **Recommended**: 4GB RAM, 2 CPU cores
- **For GPU work**: Add GPU hardware
## Usage Examples
### For AI Models
```python
import requests
# Base URL of your HuggingFace Space
BASE_URL = "https://your-username-ubuntu-sandbox.hf.space"
# Execute a command
response = requests.post(
f"{BASE_URL}/api/execute",
json={"command": "python3 -c 'print(\"Hello from AI!\")'"}
)
print(response.json())
# Create a file
requests.post(
f"{BASE_URL}/api/create",
json={
"filename": "ai_project.py",
"content": "print('AI created this!')"
}
)
# Run the created file
result = requests.post(
f"{BASE_URL}/api/execute",
json={"command": "python3 ai_project.py"}
)
print(result.json())
```
### For JavaScript/Node.js
```javascript
const BASE_URL = "https://your-username-ubuntu-sandbox.hf.space";
// Execute command
fetch(`${BASE_URL}/api/execute`, {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({command: 'node --version'})
})
.then(response => response.json())
.then(data => console.log(data));
// Create Node.js app
fetch(`${BASE_URL}/api/create`, {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
filename: 'app.js',
content: 'console.log("AI is coding!");'
})
});
```
## Advanced Configuration
### Custom Dockerfile
If you need additional system packages, modify the Dockerfile:
```dockerfile
# Add to your Dockerfile after the existing apt-get install
RUN apt-get update && apt-get install -y \
your-custom-package \
another-package \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
```
### Custom Python Packages
Add to `requirements.txt`:
```
your-custom-package==1.0.0
another-dependency==2.0.0
```
### Environment Variables
Set in your space's `Settings > Variables` tab:
```
INSTALL_TOOLS=true
AI_FRIENDLY_MODE=true
COMMAND_TIMEOUT=60
```
## Troubleshooting
### Build Issues
- **Package installation fails**: Check if packages exist in Ubuntu 22.04 repos
- **Memory errors**: Increase hardware or reduce package count
- **Build timeout**: Split into smaller Docker layers
### Runtime Issues
- **Commands fail**: Check if packages are installed in Dockerfile
- **API not responding**: Verify app.py is correct and dependencies installed
- **Permission errors**: Ensure proper file permissions in Dockerfile
### Performance Issues
- **Slow response**: Check hardware configuration
- **Memory usage**: Monitor with `htop` command
- **Disk space**: Clean up temporary files
## Security Considerations
### What's Protected
- **Container isolation**: Your space is isolated from other spaces
- **Resource limits**: Prevents resource exhaustion
- **No root access**: Commands run as non-root user
- **Timeout protection**: Long-running commands are terminated
### Best Practices
- **Monitor usage**: Check logs regularly
- **Clean up**: Remove temporary files
- **Backup important work**: Files may be cleaned up
- **Don't store sensitive data**: This is a public environment
## Monitoring and Maintenance
### Check System Health
```bash
# Check system resources
system_info
# Check running processes
ps aux
# Check disk usage
df -h
# Check memory usage
free -h
```
### View Logs
```bash
# Application logs
tail -f /home/user/workspace/logs/sandbox.log
# System logs
journalctl -f
```
### Maintenance Tasks
```bash
# Clean temporary files
rm -rf /home/user/workspace/temp/*
# Check for old sessions
ps aux | grep bash
# Update package cache
apt update
```
## Integration Examples
### GitHub Actions Integration
```yaml
name: Test in Ubuntu Sandbox
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Test in Sandbox
run: |
curl -X POST "https://your-space.hf.space/api/execute" \
-H "Content-Type: application/json" \
-d '{"command": "python3 -m pytest tests/"}'
```
### CI/CD Pipeline
```python
# Example CI/CD integration
def deploy_to_sandbox():
# Build and test
requests.post("/api/execute",
json={"command": "python3 setup.py test"})
# Create Docker image
requests.post("/api/execute",
json={"command": "docker build -t myapp ."})
# Deploy
requests.post("/api/execute",
json={"command": "docker run -d -p 80:80 myapp"})
```
## Support and Resources
### Getting Help
- **Space Issues**: Check HuggingFace Space logs
- **Technical Questions**: Review the README.md documentation
- **Feature Requests**: Submit through space repository
### Useful Commands
```bash
# Environment information
python3 /home/user/workspace/environment_info.py
# Install additional tools
/home/user/workspace/install_tools.sh
# Check system status
system_info
```
### Community
- **HuggingFace Forum**: [discuss.huggingface.co](https://discuss.huggingface.co)
- **Documentation**: [huggingface.co/docs/spaces](https://huggingface.co/docs/spaces)
- **GitHub**: [github.com/huggingface/gradio](https://github.com/huggingface/gradio)
---
**Ready to deploy your Ubuntu Sandbox Environment! π**
This guide should help you get your AI-accessible development environment up and running quickly. For specific issues, check the troubleshooting section or refer to the main README.md documentation. |