example.com is not listed, so it does not resolve and the second command exits
with a nonzero code. The last line prints ['pypi.org', 'files.pythonhosted.org'].
allow_egress requires SDK 0.10.0 or later. Over HTTP, send allow_egress in
POST /vms.
Write the list
A list holds up to 256 entries. Hostnames are not case-sensitive, and
sandbox.info.allow_egress returns them in lowercase without duplicates.
These entries are refused with InvalidRequestError (400), and the message
names the entry:
- URLs, ports, and paths, such as
https://pypi.orgorpypi.org:443. - IPv6 addresses.
- A bare
*. To allow everything, leaveallow_egressout, or pass["0.0.0.0/0"], which means the same: no list. - Private and reserved ranges, such as
10.0.0.0/8,192.168.0.0/16, and169.254.0.0/16. Sandboxes cannot reach these with or without a list.
ValueError before any request.
What a hostname covers
A hostname entry is matched against the name your client sends: the TLS server name for HTTPS, or theHost header for HTTP. Package managers, git over HTTPS,
and HTTP APIs send it, so a hostname entry is enough for them.
Downloads often redirect to a content host with a different name, and those names
can change. If a tool reports that it cannot resolve a name, add that name to the
list.
Other protocols do not carry a hostname: SSH, database protocols, mail, and raw
TCP. To reach those servers, list their IPv4 address or CIDR. Clone repositories
over HTTPS rather than SSH. HTTP proxy requests (
CONNECT) are refused.
DNS answers only the listed names, with IPv4 addresses. Every other name fails to
resolve, including queries sent directly to a public resolver.
Change the policy while the sandbox runs
set_egress() replaces the sandbox’s whole outbound policy. Nothing is merged
with the previous list.
sandbox.info.
A common pattern is to install dependencies with the internet open, then limit
the sandbox before running code you do not trust:
PUT /vms/{id}/egress.
Forks, snapshots, and archives
Forks, sandboxes restored from a snapshot, and unarchived sandboxes keep the list. To give a restored sandbox a different list, pass it at creation:allow_egress, the restored sandbox keeps the snapshot’s list. Call
set_egress() on it to change or remove the list.
When a connection is blocked
- A name that is not listed does not resolve. Tools report errors such as
Could not resolve host(curl, git) orEAI_AGAIN(npm). - An HTTPS or HTTP connection to an address whose name is not listed is reset.
- Other traffic to an address that is not listed is dropped, and the connection waits until the client’s own timeout. Set finite connection timeouts.
github.com also allows a git push to it. List only the hosts the task needs.
When you are finished: