Skip to main content

Overview

SmolVM provides expose_local() to forward TCP ports from the guest VM to localhost on your host machine. This allows you to access services running inside the VM (like web servers, databases, or APIs) from your host.

Basic Port Forwarding

Expose a guest port to localhost:

Automatic Port Allocation

Omit host_port to let SmolVM choose an available port:
Automatic port allocation is useful when the desired port might already be in use, or when running multiple VMs simultaneously.

Method Signature

Transport Methods

SmolVM automatically selects the best transport method:
Uses Linux nftables for high-performance port forwarding:
Advantages:
  • Native Linux networking
  • Higher performance
  • Lower overhead
You don’t need to choose the transport method manually. SmolVM tries nftables first and falls back to SSH tunnels automatically.

Multiple Port Forwards

Expose multiple services from the same VM:

Removing Port Forwards

Manually remove a port forward before VM shutdown:

Method Signature

Port forwards are automatically cleaned up when the VM stops or the context manager exits. Manual cleanup is only needed for long-running VMs.

Real-world Example: OpenClaw Dashboard

From the OpenClaw integration example:

Security Considerations

Localhost-only Binding

expose_local() only binds to 127.0.0.1 (localhost), NOT to 0.0.0.0. Services are NOT exposed to your network.
If you need to expose to your network, you must set up additional forwarding outside of SmolVM.

Port Conflicts

expose_local() handles port conflicts gracefully:

Troubleshooting

Port Forward Not Reachable

If expose_local() succeeds but the port is not reachable:
1

Verify the service is running

2

Check the service binds to the correct interface

Services must bind to 0.0.0.0 or the guest IP, NOT 127.0.0.1 only:
3

Test connectivity from inside the guest

Permission Errors (nftables)

If you see permission errors related to nftables:
SmolVM will automatically fall back to SSH tunnels. To enable nftables:

Next Steps

Environment Variables

Inject configuration into VMs at runtime

AI Agent Integration

Build secure sandboxes for AI agents

Custom Images

Create custom VM images with pre-installed services