Control network access
Decide which hosts a sandbox can reach, change that while it runs, and see what it tried to reach. A per-sandbox egress proxy, which runs beside the sandbox rather than inside it, enforces the policy, and the host firewall backs it.
| Mode | The sandbox can reach |
|---|---|
open | Any host. |
strict | The hosts in allowDomains, plus the model endpoint and providers the platform provisioned into the sandbox. |
blocked | No outbound internet. |
Every mode, blocked included, reaches the Tangle control plane without listing it: sandbox.tangle.tools and its exec origins, router.tangle.tools for model calls, and the Hub and workflow routes on id.tangle.tools. A sandbox can create sibling sandboxes or publish a preview link under any policy.
From inside a sandbox, the control plane accepts only its owner’s credentials: the sandbox’s own key, any key of the owner’s account, and for a team sandbox the team’s keys. A key of any other account gets a 403 with code EGRESS_REQUEST_REFUSED and policy sandbox-owner, in every mode.
What a sandbox reaches by default
A sandbox created without a policy runs strict plus a built-in list of developer hosts:
- package registries: npm, Yarn, PyPI, crates.io, RubyGems and the Go proxy;
- git hosts: GitHub (including
codeload.github.comand**.githubusercontent.com), GitLab and Bitbucket; - container registries: GitHub Packages,
ghcr.ioand Docker Hub; - CDNs:
*.cloudflare.comand**.fastly.net; - the model endpoints the platform provisioned.
A team sandbox created without a policy inherits the team’s default policy. open is honored only when you or your team set it on purpose; it is never the fallback.
An explicit strict policy drops the built-in list. npm install then fails unless you list the registry, or add includeImplicitDomains: true to keep the list.
Lock a build to the hosts it needs
import { Sandbox } from "@tangle-network/sandbox";
const client = new Sandbox({
apiKey: process.env.TANGLE_API_KEY!,
baseUrl: "https://sandbox.tangle.tools",
});
const box = await client.create({
name: "locked-build",
egressPolicy: {
mode: "strict",
allowDomains: ["registry.npmjs.org", "github.com"],
},
});
try {
await box.exec("git clone --depth 1 https://github.com/tangle-network/sandbox-demo demo");
const build = await box.exec("cd demo && npm install && npm test", { timeoutMs: 5 * 60_000 });
console.log(build.exitCode, build.stdout.slice(-400));
} finally {
await box.delete();
}From the CLI, tangle sandbox create --allow-domain <hosts...> sets strict with those hosts and always adds the built-in list above, so GitHub and gist.github.com stay reachable. To change a running sandbox’s policy, use the SDK or the REST routes below.
Domain patterns
| Pattern | Matches |
|---|---|
api.github.com | That host only. |
*.githubusercontent.com | githubusercontent.com and every subdomain at any depth. |
**.githubusercontent.com | Subdomains only, not githubusercontent.com itself. |
includeImplicitDomains: true merges the built-in list into a strict policy. That list includes github.com, gist.github.com and gitlab.com, which makes any public repository readable and a gist an allowed destination, so keep it to trusted development sandboxes.
The number of allowDomains entries is capped; see Limits.
Private addresses
A host that resolves to a private or CGNAT address is refused unless you name the ranges it may use. The exception applies only to that domain and those exact ranges, not to other domains at the same address.
import assert from "node:assert/strict";
import { Sandbox } from "@tangle-network/sandbox";
const client = new Sandbox({
apiKey: process.env.TANGLE_API_KEY!,
baseUrl: "https://sandbox.tangle.tools",
});
const box = await client.create({ agent: false, maxLifetimeSeconds: 300 });
try {
await box.egress.update({
mode: "strict",
allowDomains: [
"api.github.com",
{ domain: "build.internal", allowPrivateIps: ["10.203.1.0/24"] },
],
});
const effective = await box.egress.get();
assert.equal(effective.source, "sandbox");
assert.equal(effective.policy.mode, "strict");
assert(effective.policy.allowDomains?.includes("api.github.com"));
const buildRule = effective.policy.allowDomains?.find(
(rule) => typeof rule !== "string" && rule.domain === "build.internal",
);
assert(buildRule && typeof buildRule !== "string");
assert.deepEqual(buildRule.allowPrivateIps, ["10.203.1.0/24"]);
console.log(buildRule.domain, buildRule.allowPrivateIps);
} finally {
await box.delete();
}Change the policy while the sandbox runs
import assert from "node:assert/strict";
import { Sandbox } from "@tangle-network/sandbox";
const client = new Sandbox({
apiKey: process.env.TANGLE_API_KEY!,
baseUrl: "https://sandbox.tangle.tools",
});
const box = await client.create({ agent: false, maxLifetimeSeconds: 300 });
try {
const before = await box.egress.get();
assert(["sandbox", "team", "platform"].includes(before.source));
await box.egress.update({ mode: "strict", allowDomains: ["registry.npmjs.org"] });
const after = await box.egress.get();
assert.equal(after.policy.mode, "strict");
assert.equal(after.source, "sandbox");
assert(after.policy.allowDomains?.includes("registry.npmjs.org"));
console.log(before.source, after.policy.mode, after.source);
} finally {
await box.delete();
}update() restarts the sandbox’s proxy, which interrupts outbound connections for a few seconds and starts a new activity window. Read denials() and activity() before you change the policy.
Install, then cut the network
Untrusted code should run without network access. Install under a strict policy, then switch to blocked, which leaves only the Tangle control plane reachable:
import assert from "node:assert/strict";
import { Sandbox } from "@tangle-network/sandbox";
const client = new Sandbox({
apiKey: process.env.TANGLE_API_KEY!,
baseUrl: "https://sandbox.tangle.tools",
});
const box = await client.create({ agent: false, maxLifetimeSeconds: 300 });
try {
await box.write("app/package.json", JSON.stringify({ name: "offline-job", version: "1.0.0", private: true, scripts: { test: "node -e \"console.log('offline build complete')\"" } }));
const prepared = await box.exec("cd app && npm install --package-lock-only --ignore-scripts && npm ci");
assert.equal(prepared.exitCode, 0, prepared.stderr);
await box.egress.update({ mode: "blocked" });
const result = await box.exec("cd app && npm test");
assert.equal(result.exitCode, 0, result.stderr);
assert(result.stdout.includes("offline build complete"));
const blocked = await box.exec("curl -sS -m 5 https://example.com");
assert.notEqual(blocked.exitCode, 0);
console.log(result.stdout);
} finally {
await box.delete();
}Build an allowlist from what was refused
A refused request gets a 403 whose JSON body names the cause:
{"code":"EGRESS_DOMAIN_NOT_ALLOWED","host":"github.com","policy":"allowlist","nextStep":"Add github.com to egressPolicy.allowDomains"}policy is the rule that refused it: allowlist, secrets for a credential the proxy would not hand over, or sandbox-owner for a Tangle key of an account other than the sandbox’s owner. box.egress.denials() lists every refused host, newest first, with how often. Start strict with nothing allowed, run the build once, and read the refusals:
import assert from "node:assert/strict";
import { Sandbox } from "@tangle-network/sandbox";
const client = new Sandbox({
apiKey: process.env.TANGLE_API_KEY!,
baseUrl: "https://sandbox.tangle.tools",
});
const box = await client.create({ agent: false, maxLifetimeSeconds: 300, egressPolicy: { mode: "strict", allowDomains: [] } });
try {
const refused = await box.exec("curl -sS -m 5 https://example.com");
assert.notEqual(refused.exitCode, 0);
const deadline = Date.now() + 15_000;
let denials = await box.egress.denials({ limit: 50 });
while (!denials.some((item) => item.host === "example.com") && Date.now() < deadline) {
await new Promise((resolve) => setTimeout(resolve, 500));
denials = await box.egress.denials({ limit: 50 });
}
assert(denials.some((item) => item.host === "example.com" && item.count > 0));
for (const denial of denials) console.log(denial.host, denial.count, denial.rejectedBy);
} finally {
await box.delete();
}Then allow the hosts you trust:
import assert from "node:assert/strict";
import { Sandbox } from "@tangle-network/sandbox";
const client = new Sandbox({
apiKey: process.env.TANGLE_API_KEY!,
baseUrl: "https://sandbox.tangle.tools",
});
const box = await client.create({ agent: false, maxLifetimeSeconds: 300, egressPolicy: { mode: "strict", allowDomains: [] } });
try {
const before = await box.exec("curl -sS -m 5 https://github.com");
assert.notEqual(before.exitCode, 0);
await box.egress.update({ mode: "strict", allowDomains: ["github.com", "codeload.github.com", "registry.npmjs.org"] });
const policy = await box.egress.get();
assert(policy.policy.allowDomains?.includes("github.com"));
const allowed = await box.exec("curl -fsS -m 15 -o /dev/null -w '%{http_code}' https://github.com");
assert.equal(allowed.exitCode, 0, allowed.stderr);
assert.equal(allowed.stdout.trim(), "200");
console.log("GitHub request succeeds after updating the allowlist");
} finally {
await box.delete();
}Prove what a sandbox reached
denials() is best effort: an empty list can mean nothing was refused or that the proxy log could not be read. For an audit or a benchmark control arm, use activity(). It lists allowed and refused hosts and says whether the record is complete.
import assert from "node:assert/strict";
import { Sandbox } from "@tangle-network/sandbox";
const client = new Sandbox({
apiKey: process.env.TANGLE_API_KEY!,
baseUrl: "https://sandbox.tangle.tools",
});
const box = await client.create({ agent: false, maxLifetimeSeconds: 300, egressPolicy: { mode: "blocked" } });
try {
const refused = await box.exec("curl -sS -m 5 https://example.com");
assert.notEqual(refused.exitCode, 0);
const activity = await box.egress.activity({ limit: 500 });
assert.equal(activity.complete, true, activity.incompleteReasons.join(", "));
assert(Array.isArray(activity.destinations));
for (const destination of activity.destinations) console.log(destination.action, destination.host, destination.count);
console.log("Read complete egress activity");
} finally {
await box.delete();
}An empty destinations list with complete: true is evidence the sandbox reached nothing. With complete: false it proves nothing. activity() answers 409 when egress control is not enabled for the sandbox.
box.egress.usage({ month }) returns the sandbox’s egress bytes and charge for a calendar month. Rates are on Pricing.
Keep credentials out of the sandbox
A secret can stay with the egress proxy: the sandbox holds a placeholder, and the proxy puts the real value on requests to the hosts you name. Store it with its hosts and select it by name:
await client.secrets.create("HF_TOKEN", process.env.HF_TOKEN!, { hosts: ["huggingface.co"] });
const box = await client.create({
secrets: ["HF_TOKEN"],
egressPolicy: { mode: "strict", allowDomains: ["huggingface.co"] },
});
await box.exec(`curl -s -H "Authorization: Bearer $HF_TOKEN" https://huggingface.co/api/whoami-v2`);A strict policy does not reach the secret’s host for you; list it in allowDomains. From the CLI, select a proxy-held secret at create with --proxy-secret '<json>'. Only a proxySecrets binding, which --proxy-secret sends, can limit the methods and paths that carry the value; the hosts form above sends it on any method and path to those hosts. How each custody mode works, the presentation types and what the proxy masks in responses are on Secrets.
Coding agents behind a strict policy
A coding agent’s model calls go to the endpoint provisioned into the sandbox, which strict mode allows. When the agent uses your own subscription or a coding plan endpoint, list that provider’s host:
egressPolicy: {
mode: "strict",
allowDomains: ["api.anthropic.com", "registry.npmjs.org", "github.com"],
}See Run a coding agent in a sandbox for the agent side.
REST routes
curl -X PATCH "https://sandbox.tangle.tools/v1/sandboxes/$SANDBOX_ID/egress" \
-H "Authorization: Bearer $TANGLE_API_KEY" \
-H "Content-Type: application/json" \
-d '{"mode":"strict","allowDomains":["registry.npmjs.org"]}'| Route | Purpose |
|---|---|
PATCH /v1/sandboxes/{id}/egress | Change the policy on a running sandbox. The body merges into the current policy. |
GET /v1/sandboxes/{id}/egress/denials | Refused hosts, newest first. |
GET /v1/sandboxes/{id}/egress/activity | Allowed and refused hosts, with completeness. |
GET /v1/sandboxes/{id}/egress/usage | A month’s egress bytes and charge. |
PUT /v1/teams/{id}/egress | The team’s default policy (team owners and admins). |
Python
Python has egress_get(), egress_update(EgressPolicy(mode, allow_domains, include_implicit_domains)) and egress_denials(limit). It has no activity or usage, and EgressPolicy has no private-address entries. Read them with client.fetch, which returns the raw response and does not raise on an error status:
import os
from tangle_sandbox import Sandbox, SandboxStatus
with Sandbox(
api_key=os.environ["TANGLE_API_KEY"],
base_url="https://sandbox.tangle.tools",
) as client:
created = client.fetch("POST", "/v1/sandboxes", json={
"agent": False, "maxLifetimeSeconds": 600,
}).raise_for_status().json()
try:
box = client.get(created["id"])
assert box is not None
box.wait_for(SandboxStatus.RUNNING)
response = client.fetch("GET", f"/v1/sandboxes/{box.id}/egress/activity", params={"limit": 500})
response.raise_for_status()
activity = response.json()["activity"]
assert activity["complete"] is True, activity.get("incompleteReasons")
assert isinstance(activity["destinations"], list)
print(activity["complete"], activity["destinations"])
finally:
client.fetch("DELETE", f"/v1/sandboxes/{created['id']}").raise_for_status()Next
- Store secrets and give sandboxes credentials
- How Tangle keeps credentials out of the agent: the threat model and a measured boundary test.
- Isolation, privacy and compliance
- Run a coding agent in a sandbox