On-demand port forwarding from host to a running sandbox's HTTP and nREPL ports.
Sandboxes run isolated in Docker with internal ports not exposed to the host. To browse the ERP web UI or connect an editor to nREPL, we need a way to forward host ports into a specific sandbox.
Use host-side socat processes to forward TCP connections from host ports to the target sandbox container's IP.
Host Docker Network (orcha-sandbox-foo_default)
┌─────────────────┐ ┌──────────────────────────────────────┐
│ │ │ │
│ browser │ │ claude container (172.20.0.4) │
│ │ │ │ └─ ERP listening on :8888 │
│ ▼ │ │ │
│ localhost:8888 │ │ postgres (172.20.0.2) │
│ │ │ │ localstack (172.20.0.3) │
│ ▼ │ │ │
│ socat ─────────────────────────▶ 172.20.0.4:8888 │
│ (background) │ │ │
└─────────────────┘ └──────────────────────────────────────┘
bb sandbox:expose <name> # Forward host ports to sandbox
bb sandbox:unexpose # Stop forwarding
bb sandbox:exposed # Show which sandbox is currently exposed
| Host Port | Container Port | Service |
|---|---|---|
| 7777 | 7777 | HTTP |
| 8888 | 8888 | ERP |
| 9999 | 9999 | HTTP |
| 7888 | 7888 | nREPL |
.worktrees/
└── .sandbox-expose/
├── current # Contains feature name (e.g., "booking-ocr")
└── pids # Space-separated socat PIDs
bb sandbox:expose foodocker ps --filter name=orcha-sandbox-foo-claude -qdocker inspect.worktrees/.sandbox-expose/current.worktrees/.sandbox-expose/pidsbb sandbox:unexposebb sandbox:exposedcurrent file exists and PIDs are still running: print feature namesocat must be installed on the hostexpose handles this by overwriting