Skip to content

Egress is the traffic a miniVM sends out. In onshore.sh it is closed by default: a miniVM reaches nothing until its template allows it. You open it domain by domain: in the template, at create, or while the miniVM runs.

List the domains in the egress section of your template’s minisandbox.yaml:

egress:
presets: [github, npm, pypi]
allow:
- api.example.com
- "*.example.org"
  • presets are fixed lists of domains, maintained by onshore.sh (below).
  • allow lists your own domains. A leading *. allows every subdomain. Write names in lowercase. IP addresses are refused.
  • At most 256 domains in total, presets included.
  • No egress section means no egress at all.

The list applies to the build (setup and start) and to every miniVM of the template version. To change it for every new miniVM, edit the recipe and run ons template build again. To change it for one miniVM, see below. See Templates and the minisandbox.yaml reference.

Preset Domains
github github.com, api.github.com, codeload.github.com, uploads.github.com, raw.githubusercontent.com, objects.githubusercontent.com, release-assets.githubusercontent.com, github-cloud.githubusercontent.com
npm registry.npmjs.org, registry.yarnpkg.com, repo.yarnpkg.com, nodejs.org
pypi pypi.org, files.pythonhosted.org
crates crates.io, index.crates.io, static.crates.io, static.rust-lang.org
ubuntu archive.ubuntu.com, *.archive.ubuntu.com, security.ubuntu.com, ports.ubuntu.com, snapshot.ubuntu.com
docker-hub registry-1.docker.io, auth.docker.io, index.docker.io, production.cloudflare.docker.com, production.cloudfront.docker.com
ghcr ghcr.io, pkg-containers.githubusercontent.com
llm-apis api.anthropic.com, api.openai.com, platform.claude.com, claude.ai, generativelanguage.googleapis.com, api.mistral.ai, openrouter.ai, opencode.ai, models.dev

The base templates already open presets: dev-base allows ubuntu, github, docker-hub, ghcr, pypi, npm and crates, and dev-agents adds llm-apis. A recipe from: them does not inherit this: write the presets you need in your own recipe.

A create can narrow or widen the template’s list for that miniVM only.

Terminal window
ons create --json --template <template-name> --egress-allow pypi
ons create --json --template <template-name> --egress-add api.example.com
  • <template-name> is the name of your template.
  • --egress-allow keeps only these names or presets. Each one must be allowed by the template (a template’s *.domain allows its subdomains). A name outside it is refused with 403 egress_exceeds_template.
  • --egress-add also allows names or presets the template does not allow, up to your organization’s ceiling (any domain name, unless onshore.sh support limited it to presets: below).
  • Both are repeatable. Quote wildcards ('*.example.com'): the shell expands an unquoted *.

The API takes the same as egress: {mode, allow, add} on the create body: see the API reference. With the E2B SDK, close all egress, or pass E2B’s network.allowOut:

from e2b import Sandbox
sbx = Sandbox.create(template="<template-name>", allow_internet_access=False)
  • allow_internet_access: false closes all egress. true is refused with 400 when the template allows nothing and the create adds nothing.
  • network.allowOut takes domain names: a name the template allows narrows the list, a name outside it is added, within your ceiling. network.denyOut takes only ["0.0.0.0/0"], alone to close egress. IP addresses and CIDR blocks are refused with 400.

A miniVM’s list also holds its system hosts, which no change removes: the onshore.sh API when it has a self token, and the hosts of the AI accounts bound to it. Open egress (*) is never available.

You can change the list of a running or paused miniVM without rebuilding its template:

Terminal window
ons egress ls <minivm-id>
ons egress allow <minivm-id> pypi api.example.com
ons egress deny <minivm-id> api.example.com
  • <minivm-id> is the id ons create printed (ons ls lists yours).
  • ls shows the effective list: from the template, added, removed, and the system hosts.
  • allow adds names or presets, up to your organization’s ceiling. deny removes them, the template’s included.
  • A running miniVM has the change applied before ons answers (else 503 egress_not_applied, below). A paused miniVM gets it when it resumes, before any of its code runs: ls shows it as pending until then.

The API routes are GET and PATCH /v2/sandboxes/{id}/egress, and E2B’s PUT /sandboxes/{id}/network (Sandbox.updateNetwork). See the API reference.

Limits:

  • At most 10 changes per minute per miniVM.
  • At most 256 names in the list, system hosts included. Group names with *.domain.
  • A removal that a running miniVM’s host cannot apply within 10 minutes pauses that miniVM (pauseReason: egress_unapplied). Its next resume applies the new list.
Error Cause
403 egress_presets_only Your organization is limited to presets, and the name is not a preset host.
409 egress_system_host You tried to remove a system host (the API of a self token, an AI account’s host).
409 egress_host_has_credential The host has an egress credential. Create the miniVM without the credential instead.
409 egress_update_unsupported The miniVM runs where egress cannot change at run time (a Hybrid pool, or an older runner).
409 egress_not_managed The miniVM was created before egress could change at run time. Create a new one.
409 minivm_moving The miniVM is pausing or resuming. Retry.
429 egress_rate_limit More than 10 changes in a minute. Wait Retry-After seconds.
503 egress_not_applied The change is stored, but the miniVM’s host has not applied it yet. It keeps being sent; retry after Retry-After seconds to check.

Code in a miniVM can ask you for a name it does not reach. Nothing opens until you, or one of your rules, approve it. Inside the miniVM:

Terminal window
msb-egress check <name>
msb-egress request <name> "<reason>"
  • <name> is a domain name or a preset. request takes up to 10 of them, then <reason>: one line, 1 to 280 characters, telling you why the miniVM needs them.
  • check exits 0 when the miniVM may reach the name, 1 when it may not.
  • request waits for the answer, 15 minutes by default (--timeout, from 1m to 1h). It exits 0 approved, 1 denied or refused, 2 expired or timed out, 3 on an error.
  • msb-egress is in every template built now; rebuild an older template to get it. It works in a miniVM created with ons create --agents, and in agent runs.

Limits per miniVM: one request every 10 seconds, at most 10 pending at once and 500 in a day. A request expires after 15 minutes unless you decide it.

From your machine, answer the requests:

Terminal window
ons egress requests --wait
ons egress approve <request-id>
ons egress approve <request-id> --always
ons egress reject <request-id> --message "<message>"
  • <request-id> is the request’s id (egr_…), as ons egress requests lists it. --wait waits until a new request arrives (15 minutes by default, then exits 124).
  • approve shows the miniVM, the exact hosts the request opens and its reason, then asks you. Add names after the id to approve only some of them, and --yes to skip the question in scripts. Approving widens the miniVM’s list like ons egress allow.
  • --always also adds the names to your organization’s auto-approve rules: later requests for them are approved at once. Only an owner, or a key an owner created, may do it.
  • <message> is told to the miniVM, at most 280 characters.

In the console, Egress lists the pending requests, the last 30 days of decisions, and the auto-approve rules, which owners edit (at most 256 names, *.domain covers the names below it). Owners see every request of the organization; members, those of their own miniVMs.

API routes: POST /v2/sandboxes/{id}/egress/requests and the /v2/egress/requests routes in the API reference.

Terminal window
ons egress denials <minivm-id>

Without ons, for example with the E2B SDK, call the API with your key:

Terminal window
curl -fsS https://api.onshore.sh/v2/sandboxes/<minivm-id>/egress/denials -H "X-API-Key: <your-api-key>"
  • <minivm-id> is the miniVM’s id. With the E2B SDK it is sbx.sandbox_id (sbx.sandboxId in JavaScript).
  • <your-api-key> is your onshore.sh API key, the one in E2B_API_KEY or ONS_API_KEY.

The answer is {denials: [{name, count, firstAt, lastAt}], suppressed}: see the API reference.

It lists the names the miniVM tried to resolve and egress refused, newest first, with a count, kept 30 days. A name can show up to a minute after its refusal. The names come from inside the miniVM: treat them as untrusted.

Inside the miniVM, a refused name answers DNS REFUSED. A client that sends EDNS also gets an extended error (Blocked) that names the command to ask for it: msb-egress request <name> "<reason>".

onshore.sh support can limit an organization to the hosts of the built-in presets, for example after abuse. A card or a payment does not change it. Then a template, a create, a change or a request that names another host is refused with 403 egress_presets_only (a request is refused). Use presets only, or write to support@onshore.sh.

On a Hybrid pool, a create can only narrow the template’s egress: a name outside it is refused with egress_exceeds_template (400 for --egress-add and network.allowOut, 403 for --egress-allow). Egress cannot change at run time (409 egress_update_unsupported).

  • Only allowed names resolve. The miniVM uses a resolver run by the platform. Other names are designed to be answered locally and never sent upstream (planned).
  • Only the addresses an allowed name resolves to are opened, for a limited time. Raw IP addresses, other resolvers and IPv6 are dropped.
  • An allowed name that resolves to a private address is not opened (planned).
  • miniVMs cannot reach each other, nor the host they run on.

These are dropped for every miniVM, whatever its template allows:

  • SMTP: ports 25, 465 and 587. You cannot send email directly from a miniVM; use your email provider’s HTTPS API.
  • Cloud metadata addresses.
  • Private address ranges.

Allow lists work on addresses. When an allowed name shares its addresses with other names (a CDN, for example), the miniVM can also reach those other names on the same addresses.

Each miniVM’s egress is capped at 25 Mbit/s per vCPU, at least 50 Mbit/s and at most 400 Mbit/s. It can burst to twice its cap for 30 seconds.

Ingress is free. Egress includes a monthly allowance per organization, then is billed per GB. See Pricing.

Environment variables or egress credentials

Section titled “Environment variables or egress credentials”

ons create, ons run, ons agent new and ons agent start --template can set environment variables of the miniVM they create. Like an egress credential, a value comes from your environment or a file, never from the command line:

Terminal window
ons create --json --env <VAR> --env-file <path>

<VAR> is the name of a variable set in your own environment: the miniVM gets the same name and value. <path> is a dotenv file of KEY=VALUE lines (optional export, # comments, single quotes taken literally, double quotes with escapes only). A later file wins over an earlier one, and --env wins over any file. Your variables win over the template’s of the same name. Values are taken as written: ${...} is never expanded.

The variables are set when the miniVM is created only: ons agent start <id> on an existing miniVM refuses them. Names starting with MSB_ or E2B_ are refused. A miniVM takes at most 256 variables, 32 KiB per value and 64 KiB in total, the template’s env included.

--env KEY=VALUE is refused. When a name or path could be a value typed by mistake, an error names the flag by its position (--env #2) instead. This only recognises exported variables, so pass names, not $VAR.

With the E2B SDKs, pass the variables as envs when you create the miniVM. The same limits apply:

import os
from e2b import Sandbox
sbx = Sandbox.create(envs={"<VAR>": os.environ["<VAR>"]})
print(sbx.commands.run("printenv <VAR>").stdout)

<VAR> is the name of the variable. Read its value from your own environment or secret store, never write it in your code.

An environment variable is readable by everything in the miniVM, including the agent. To keep a secret out of the miniVM, use an egress credential instead: the miniVM only sees the placeholder msb-egress-credential.

An egress credential lets a miniVM call an HTTPS service with a secret it never sees. You give the secret when you create the miniVM. The platform adds it as a header to the miniVM’s requests to one host, on their way out. Code in the miniVM sends the placeholder msb-egress-credential instead.

Terminal window
export GH_TOKEN=<your-github-token>
ons create --json \
--egress-credential api.github.com=authorization:bearer:env:GH_TOKEN \
--egress-credential github.com=authorization:github-basic:env:GH_TOKEN

<your-github-token> is a GitHub token. ons reads the value from the environment variable (env:GH_TOKEN) or from a file (file:<path>), never from the command line.

The format is <host>=<header>:<scheme>env:<VAR>:

Part Meaning
<host> The host the header goes to. It must be on the miniVM’s allow list (the template’s, with what the create adds): a credential never widens egress.
<header> The header name, for example authorization.
<scheme> Optional. bearer: sends Bearer <value>. github-basic: sends what git over HTTPS sends to GitHub. Nothing: the value as is.

Then, in the miniVM:

Terminal window
GH_TOKEN=msb-egress-credential gh api user
  • Up to 16 credentials per miniVM.
  • The platform installs its own certificate authority in the miniVM’s trust store to add the header to HTTPS requests. Tools that use the system trust store work unchanged.
  • Keys for Anthropic and OpenAI do not go here. Add them as AI accounts with ons auth add-key: see Agent runs.

Some clients cannot send a placeholder header. --egress-route <host>=<route> also serves the host’s credentials on a plain HTTP address inside the miniVM, under /r/<route>. ons create --help prints the exact address. Add :/<prefix> to forward to a path prefix of the host.

You can also add a credential to a miniVM that is already running, without recreating it. Such a credential is reached on a route only: code in the miniVM calls the plain HTTP address http://172.16.0.1:8080/r/<route>/, and the platform adds the header on its way to https://<host>. Requests the miniVM sends straight to the host carry no credential.

Terminal window
export API_TOKEN=<your-api-token>
ons egress credential add <minivm-id> --host api.example.com --header authorization \
--route example bearer:env:API_TOKEN

<minivm-id> is the id ons create printed. <your-api-token> is the secret. --route names the route: 1 to 32 of a-z, 0-9 and -. Add --prefix /<prefix> to forward to a path prefix of the host. ons reads the value from the environment variable or from a file (file:<path>), never from the command line.

Then point the tool in the miniVM at the route, for example its base URL, or git:

Terminal window
git config --global url."http://172.16.0.1:8080/r/example/".insteadOf https://api.example.com/

List and remove credentials with:

Terminal window
ons egress credential ls <minivm-id>
ons egress credential rm <minivm-id> --route example

ls shows each credential’s host, header, route, prefix, origin (create or runtime) and state, never its value. rm cuts the route’s requests in flight.

  • Only an API key that can manage the miniVM can add or remove one: the miniVM’s own token cannot.
  • The miniVM must be running: a paused miniVM refuses add and rm (409). To revoke a value while paused, resume the miniVM with egressCredentials listing only the values to keep ([] clears them all, and the route answers 503 until you rm it), or kill it.
  • The host must already be on the miniVM’s allow list (ons egress allow first). These hosts are refused, as their keys come from an AI account or the GitHub binding:
    • the AI providers’ hosts api.anthropic.com, api.openai.com and chatgpt.com, always;
    • the hosts of the AI accounts bound to the miniVM;
    • github.com and codeload.github.com on a miniVM reading GitHub read-only.
  • The value is at most 8 KiB.
  • The 16 credentials per miniVM include the ones given at create. A credential given at create cannot be removed.
  • While a credential holds a host, the host cannot leave the allow list: rm the credential first.
  • Hybrid pools take credentials at create only.
  • A host takes one credential (409 egress_credential_host_taken), and a route name one host (409 egress_route_taken).
  • 409 egress_route_pending: an earlier add of the same route failed and is still being cleaned up. Retry in a minute.
  • 409 egress_credential_update_unsupported: this deployment cannot add credentials to a running miniVM. Recreate the miniVM with --egress-credential.

When the code in a miniVM must read the secret itself (a database URL, an SSH key, a service account file), give it as a file:

Terminal window
export DATABASE_URL=<your-database-url>
ons secret provide <minivm-id> DATABASE_URL --from-env DATABASE_URL

<your-database-url> is the secret. The miniVM gets the file /run/msb/secrets/DATABASE_URL, mode 0400, owned by the template’s user. --from-file <path> reads the value from a file instead. The value never goes on the command line, and onshore.sh does not store it: it goes straight to the miniVM.

Terminal window
ons secret ls <minivm-id>
ons secret rm <minivm-id> DATABASE_URL
  • The miniVM must be running. A name is A-Z, 0-9 and _, not starting with a digit, 64 characters at most, and not starting with MSB_ or E2B_. A value is at most 32 KiB; keep to about 32 files per miniVM. Providing a name again replaces the file.
  • The file lives in the miniVM’s memory: a pause keeps it, a fork does not copy it, a reset loses it.
  • Everything running as the template’s user can read it, the agent included, so it can end up in the agent’s transcript and at its model provider. For a token sent in an HTTP header, use an egress credential instead: its value never enters the miniVM.

An agent that finds, in the middle of a task, that it needs a secret can ask you for it from inside the miniVM:

Terminal window
msb-agent secret request DATABASE_URL --reason "run the migrations against staging"

If /run/msb/secrets/<NAME> already exists, it exits 0 at once and asks nothing. Under an agent run, the run goes to needs_input (kind secret), and ons agent wait exits 10 with the request. The agent needs a working model to get there: on a miniVM with no AI account bound, its run stays working. You see the request, then provide the secret or deny it:

Terminal window
ons secret requests
ons secret provide <minivm-id> DATABASE_URL --from-env DATABASE_URL --request <request-id>
ons secret deny <request-id>

<request-id> is the request’s id (scr_…), as ons secret requests prints it. The request carries only a name and a reason, written by the agent: treat them as untrusted. msb-agent secret request exits 0 once the file is there (it prints its path, never the value), 1 when denied, 2 when the request expired (--timeout, 1 minute to 1 hour, default 15 minutes) and 3 on an error. A webhook subscribed to secret.requested gets the request too. Requests are kept 30 days.

msb-agent secret request comes with the template. A template built before the platform update of 1 December 2026 lacks it: the miniVM answers unknown command "secret". Rebuild it with ons template build. ons template ls marks a template built from: a base template as outdated; one built on an image: or a dockerfile: is not marked, and needs the rebuild too. The base and agents templates onshore.sh built for your organization are rebuilt for you; one you edited and built yourself is not. ons secret provide, ls and rm need no rebuild.

You need Use The miniVM sees
A token for one host, known when you create the miniVM ons create --egress-credential the placeholder msb-egress-credential
A token for one host, for a miniVM already running ons egress credential add, reached on its route the route address only
A key for Anthropic or OpenAI an AI account, ons auth add-key a placeholder
A setting, or a secret the code must read, known when you create the miniVM --env or --env-file the value
A secret the code must read, for a miniVM already running ons secret provide a file in /run/msb/secrets
A secret the agent finds it needs during a task msb-agent secret request, then ons secret provide a file, once you provide it

GitHub repositories have a simpler path: connect the onshore.sh GitHub App with ons github connect, then create the miniVM with --metadata msb.github_repos=<owner/name>. Without the App, a public repository is cloned read-only, with no token.

With the E2B SDKs, set the same metadata key. The miniVM reaches GitHub for those repositories without any change to its egress, and git works with no token in the miniVM:

from e2b import Sandbox
sbx = Sandbox.create(metadata={"msb.github_repos": "<owner>/<name>"})
sbx.commands.run("git clone https://github.com/<owner>/<name>")

<owner>/<name> is a repository the App reaches (ons github status lists them). Separate several with commas, without spaces.

A pause keeps the credential values, also when the miniVM resumes on another server, and you send nothing again. While the miniVM is paused, the values are at rest only inside its encrypted pause snapshot, and deleted with it. They are restored before the miniVM’s code runs again.

The values are not kept, and you must send them again, after:

  • a restart of the server running the miniVM;
  • a reset of the miniVM (ons reset, where offered);
  • a fork (ons fork, where offered): a child never gets its source’s values;
  • a pause taken before its server kept values, or on a server that does not yet;
  • on a Hybrid pool, a resume from the stored pause: there the values are kept only in memory;
  • a pause during which the miniVM lost its network, for example when its server restarted.

Then requests that need a value get 503 msb_credential_unavailable, and GET /sandboxes/{id} shows egressCredentials.state: "missing".

Send the values with the resume:

Terminal window
export GH_TOKEN=<your-github-token>
ons resume <minivm-id> --egress-credential api.github.com=authorization:bearer:env:GH_TOKEN

<minivm-id> is the miniVM’s id. The flag takes the same format as on ons create. Each entry names the host and header of a credential given at create or added to the running miniVM, and the list replaces every value the miniVM holds: list every credential you still need. ons resume warns on stderr when values are still missing.

In the API, egressCredentials on a resume or connect replaces the values the miniVM holds before its code runs. [] clears them; leaving it out keeps them. On a server that does not keep values, they arrive just after the resume, so the miniVM’s code may briefly run without them. The answer shows egressCredentials: {state, rules}. For a running miniVM, you can also use PUT /sandboxes/{id}/egress-credentials. On a Hybrid pool, send the values with that call after the resume, not in it. See the API reference.