Bolt is a production-ready Python-based server for managing lightweight sandboxes on Debian/Ubuntu systems. It uses debootstrap to create sandbox environments, cgroups for resource limiting, iptables for port forwarding, and a custom TCP-based shell for remote access. The server provides a secure HTTPS API with authentication, supports project-based sandbox grouping, and includes features like port forwarding (host-to-sandbox and sandbox-to-host), resource management, and detailed status reporting.
- Sandbox Management: Create and delete sandboxes from Debian/Ubuntu base images.
- Project Grouping: Organize sandboxes into projects for better management.
- Resource Limits: Configure CPU and memory limits per project using
cgroups. - Port Forwarding: Support both host-to-sandbox and sandbox-to-host port forwarding.
- TCP Shell: Secure, token-based remote shell access to sandboxes.
- HTTPS API: Secure API with HTTP Basic Authentication and SSL/TLS.
- Systemd Integration: Runs as a systemd service under a dedicated
boltuser. - Runtime Tracking: Accurate tracking of project and sandbox creation times.
- Update Checks: Checks for server updates via an API endpoint.
- Security: Input sanitization, restricted file permissions, and namespace isolation with
unshare.
- Debian or Ubuntu server with
cgroupsenabled. - Installed packages:
debootstrap,iptables,cgroup-tools,openssl,python3,python3-pip. - Python dependencies:
flask,werkzeug,psutil,netifaces,requests. - A dedicated
boltuser for running the server.
sudo apt update
sudo apt install debootstrap iptables python3 python3-pip cgroup-tools openssl
pip3 install flask werkzeug psutil netifaces requestssudo useradd -r -s /bin/false -d /var/bolt boltsudo mkdir -p /var/bolt/sandboxes /var/bolt/projects /var/bolt/base_images /var/log/bolt /etc/bolt
sudo chown -R bolt:bolt /var/bolt /var/log/bolt
sudo chmod -R 750 /var/bolt /etc/bolt
sudo touch /var/log/bolt_server.log
sudo chown bolt:bolt /var/log/bolt_server.log
sudo chmod 640 /var/log/bolt_server.log
sudo mkdir -p /sys/fs/cgroup/cpu/bolt /sys/fs/cgroup/memory/bolt
sudo chown -R bolt:bolt /sys/fs/cgroup/cpu/bolt /sys/fs/cgroup/memory/bolt
sudo chmod -R 750 /sys/fs/cgroup/cpu/bolt /sys/fs/cgroup/memory/boltCopy the bolt_server.py script to /usr/local/bin:
sudo cp bolt_server.py /usr/local/bin/bolt_server.py
sudo chown bolt:bolt /usr/local/bin/bolt_server.py
sudo chmod 750 /usr/local/bin/bolt_server.pyCreate /etc/systemd/system/bolt.service with the following content:
[Unit]
Description=Bolt Sandbox Server
After=network.target
[Service]
User=bolt
Group=bolt
ExecStart=/usr/bin/python3 /usr/local/bin/bolt_server.py --host 0.0.0.0 --port 5000
Restart=always
RestartSec=10
Environment=PYTHONUNBUFFERED=1
[Install]
WantedBy=multi-user.targetEnable and start the service:
sudo cp bolt.service /etc/systemd/system/bolt.service
sudo chmod 644 /etc/systemd/system/bolt.service
sudo systemctl enable bolt
sudo systemctl start boltThe server generates a self-signed certificate at /etc/bolt/cert.pem and /etc/bolt/key.pem if none exist. For production, replace these with a trusted certificate from a Certificate Authority.
The server configuration is stored in /etc/bolt/config.json with the following defaults:
{
"admin_user": "admin",
"admin_password": "<hashed_password>",
"base_image_dir": "/var/bolt/base_images",
"default_distro": "debian:bullseye",
"allowed_ports": [10000, 10001, ..., 19999],
"shell_port_range": [20001, 20002, ..., 25000],
"default_resource_limits": {
"cpu_quota_us": 100000,
"memory_limit_bytes": 536870912
},
"shell_token_expiry": 3600
}- Update the admin credentials via the
/api/configendpoint. - File permissions are set to
0600for security. - Logs are written to
/var/log/bolt_server.log.
All endpoints require HTTP Basic Authentication with the admin credentials and are served over HTTPS.
- Create Project:
POST /api/projects- Payload:
{ "name": "project_name" } - Response:
201 Createdor400 Bad Request
- Payload:
- Delete Project:
DELETE /api/projects/<name>- Response:
200 OKor400 Bad Request
- Response:
- Create Sandbox:
POST /api/projects/<project_name>/sandboxes- Payload:
{ "name": "sandbox_name", "distro": "debian:bullseye" } - Response:
201 Createdor400 Bad Request
- Payload:
- Delete Sandbox:
DELETE /api/projects/<project_name>/sandboxes/<name>- Response:
200 OKor400 Bad Request
- Response:
- Start Shell:
POST /api/projects/<project_name>/sandboxes/<name>/shell- Response:
200 OKwith{ "port": <port>, "token": <token> }or400 Bad Request
- Response:
- Forward Port (Host to Sandbox):
POST /api/projects/<project_name>/sandboxes/<name>/ports- Payload:
{ "host_port": 10001, "container_port": 80 } - Response:
200 OKor400 Bad Request
- Payload:
- Remove Port Forward:
DELETE /api/projects/<project_name>/sandboxes/<name>/ports/<host_port>- Response:
200 OKor400 Bad Request
- Response:
- Reverse Port Forward (Sandbox to Host):
POST /api/projects/<project_name>/sandboxes/<name>/reverse_ports- Payload:
{ "container_port": 8080, "host_port": 10002 } - Response:
200 OKor400 Bad Request
- Payload:
- Remove Reverse Port Forward:
DELETE /api/projects/<project_name>/sandboxes/<name>/reverse_ports/<container_port>- Response:
200 OKor400 Bad Request
- Response:
- Set Resource Limits:
PUT /api/projects/<project_name>/resources- Payload:
{ "cpu_quota_us": 50000, "memory_limit_bytes": 268435456 } - Response:
200 OKor400 Bad Request
- Payload:
- Update Admin Credentials:
PUT /api/config- Payload:
{ "admin_user": "newadmin", "admin_password": "newpass" } - Response:
200 OKor400 Bad Request
- Payload:
-
Server Status:
GET /api/status-
Response:
200 OKwith system and project details -
Example:
{ "projects": [ { "name": "project1", "sandboxes": [ { "name": "sandbox1", "distro": "debian:bullseye", "created_at": "2025-05-21T10:00:00", "port_mappings": { "10001": 80 }, "reverse_port_mappings": { "8080": 10002 } } ], "resource_limits": { "cpu_quota_us": 100000, "memory_limit_bytes": 536870912 }, "created_at": "2025-05-21T09:00:00" } ], "system": { "cpu_usage": 10.5, "memory_usage": 75.2, "disk_usage": 20.1 }, "version": "1.0.0" }
-
-
Check Updates:
GET /api/update- Response:
200 OKwith{ "update_available": true, "latest_version": "1.0.1", "current_version": "1.0.0" }
- Response:
- HTTPS: Use a trusted certificate in production.
- Shell Authentication: TCP shells require a unique token, valid for 1 hour.
- Permissions: Files and directories are owned by the
boltuser with restricted permissions (750for directories,600for files). - Isolation: Sandboxes use
unsharefor namespace isolation andcgroupsfor resource limits. - Input Sanitization: All inputs are sanitized to prevent injection attacks.
- Firewall: Restrict access to ports 5000 (API) and 20001–25000 (shells) using a firewall (e.g.,
ufw).
- Check logs at
/var/log/bolt_server.logfor errors. - Ensure
cgroupsare mounted:mount -t cgroup -o cpu cpu /sys/fs/cgroup/cpu. - Verify the
boltuser has appropriate permissions. - If HTTPS fails, check certificate validity and permissions.