What you’ll build
A script that:- Starts an HTTP server inside a sandbox with port forwarding
- Builds a JSON API with multiple routes
- Exposes multiple ports for complex services
Prerequisites
- Python
- Node.js
Step 1: Start an HTTP server
Launch a box with port forwarding, start a simple HTTP server inside it, and access it from the host.- Python
- Node.js
http_server.py
- The
portsparameter maps host port 8080 to guest port 8080 over TCP sh -c "... > /dev/null 2>&1 &"starts the server as a background process with output redirected, soexec()returns immediately- You can then make HTTP requests from the host to
http://localhost:8080
Step 2: Build a JSON API
Create a multi-route JSON API inside the sandbox using Python’s built-inhttp.server or Node.js’s http module.
- Python
- Node.js
json_api.py
Port forwarding changes the VM’s network configuration, which disables outbound internet access (DNS resolution). Use standard library modules (like Python’s
http.server or Node.js’s http) that don’t require package installation. For services that need third-party packages, build a custom Docker image with your dependencies pre-installed.Step 3: Expose multiple ports
A single box can forward multiple ports — useful for running an API server alongside a metrics endpoint, or exposing admin and public interfaces.- Python
- Node.js
multi_port.py
Port forwarding reference
Python
Node.js
What’s next?
Run any language or tool
Use custom images to run Node.js, Go, shell scripts, or any CLI tool.
Handle errors and debug
Catch exceptions, handle timeouts, and debug failures.
Upload & download files
Copy files into the box for your service to use, and retrieve results.
AI agent integration
Production patterns for using BoxLite services with AI agents.

