Skip to content

Tutorials

Services and ports

Start a service inside a microVM and expose only the ports you intend to reach from the host.

Long-running services are useful for preview servers, API sandboxes, browser targets, and test dependencies.

Terminal window
mvmctl machine run --manifest . --name servicebox --port 8080:8000 -- \
python -m http.server 8000

The exact command surface may vary by backend and profile; check CLI Commands for current flags.

  • Bind only the ports you need.
  • Prefer loopback host exposure for local development.
  • Do not expose admin consoles without auth.
  • Review ingress admission and teardown audit events.
  • Stop or cold-pause the sandbox when the service no longer needs CPU.

Status: Planned lifecycle API.

sandbox = Sandbox.create(
image="nix:./flake#service",
network={"mode": "none", "ports": [{
"mapping_id": 1, "proto": "tcp", "transform": "opaque",
"host_addr": "127.0.0.1", "host": 8080,
"guest_addr": "127.0.0.1", "guest": 8000,
}]},
)
proc = sandbox.exec_background(["python", "-m", "http.server", "8000"])