Bring your own egress
Send a sandbox's outbound traffic through your own proxy, WireGuard peer, Tailscale exit node or a dedicated IP, with a kill switch.
By default a sandbox's outbound traffic leaves through Sandal's shared egress. Bring-your-own egress routes all of it through an exit you control instead, so websites and APIs see your address:
| Exit | You provide | Stored as |
|---|---|---|
| HTTP / SOCKS5 proxy | http://user:pass@host:port (or socks5://...) | a project secret |
| WireGuard | a full-tunnel wg-quick config | a project secret |
| Tailscale exit node | an OAuth client (or auth key) + the exit node's name or IP | a project secret |
| Dedicated IP | nothing: one exclusive static IP for the whole project (country, optionally city) | - |
Kill switch: while the exit is down, nothing leaves the sandbox, and never through Sandal's own address. Exec, files and ports keep working. sandal egress <id> shows the exit, its state and the measured exit IP.
Connect once (project default)#
The quickest path: make an exit the project default. Every sandbox created afterwards without its own exit leaves through it; existing sandboxes keep theirs, and a create can opt out (sandal create --no-egress-default, egressDefault: "skip" in the SDKs).
# Tailscale, in one step: checks the OAuth client, stores it sealed on this machine, sets the project default
printf '%s\n%s\n' "$TS_OAUTH_CLIENT_ID" "$TS_OAUTH_CLIENT_SECRET" | sandal egress tailscale connect --exit-node my-exit-node
# Or any exit kind
printf %s 'http://user:pass@proxy.example:8080' | sandal secrets create my-proxy --value-stdin
sandal egress default set --egress-proxy my-proxy
sandal egress default # show it
sandal egress default clear # back to Sandal's shared egress for new sandboxesFor Tailscale, create the OAuth client in the Tailscale admin console (Settings, OAuth clients) with scope auth_keys (write) and the tag (default tag:sandal-sandbox), plus devices:core (read) if Sandal should check the exit node. The tag needs tagOwners and one grant to autogroup:internet. Each sandbox joins your tailnet as its own ephemeral tagged node.
Per sandbox#
import { Sandal } from "@sandal-dev/sdk";
const sandal = Sandal.fromEnv();
// secretId/version of a project secret that holds http://user:pass@host:port (sandal secrets create ...)
const sb = await sandal.createSandbox({
name: "via-my-proxy",
egress: { proxy: { type: "http", urlRef: { secretId: process.env.PROXY_SECRET_ID!, version: "1" } } },
});
console.log(await sandal.sandboxes.getEgress(sb.id)); // exit, state, measured exit IP
console.log((await sb.exec(["curl", "-s", "https://ifconfig.me"])).stdout);Notes#
- Secrets are referenced, never sent in clear: the CLI seals them on your machine before upload.
- A dedicated IP is exclusive to your project and stays the same for every sandbox that uses it; the first use picks it from the country (and city) you name.
When an exit is refused#
The sandbox keeps its kill switch (no traffic leaves another way) and sandal egress <id> shows failed with a code:
failureCode | Meaning |
|---|---|
egress.invalid-upstream | The exit itself is not acceptable: a malformed proxy URL or WireGuard file, or (from API 13.59) a WireGuard Endpoint or a Tailscale login server on a private, link-local, cloud-metadata, CGNAT or loopback address, or a local-only name (.local, .internal, .lan, a single label). Point it at a public address or name. |
egress.secret-unavailable | The secret the exit references cannot be read in this project (deleted, or a different project). |
egress.proxy-type-mismatch | --egress-proxy-type does not match the stored URL's scheme. |
egress.tailscale-key-unavailable | The Tailscale credential could not mint a key for this sandbox. |
egress.tailscale-oauth-requires-saas | A Tailscale OAuth client works with Tailscale's own control server only; use an auth key for Headscale. |
egress.dedicated-ip-unavailable / -exhausted / -limit | Dedicated IPs are not enabled for the organization, none is free in that location, or the organization's IP limit is reached. |
The gateway checks the exit again when it connects (it resolves names then), so a name that later resolves to a private address is refused too.