Skip to content
Hexel StudioDocs

Sandbox egress

Decide which hosts your agents' code sandboxes may reach, per organization, workspace or environment; open one more destination for one sandbox; and see how Titan's kill reaches sandboxes.

On this page

Agents that run code do it in sandboxes: isolated machines that Hexel Studio creates for your organization. A sandbox can reach only what your egress policy allows. With no policy, a sandbox reaches nothing out and nothing in.

The policy is set by your administrators, never by the caller that creates the sandbox: an agent can't widen its own network. A sandbox that needs one more destination gets an egress grant for that one sandbox.

Create sandboxes

Sandboxes use the E2B API, so the stock E2B SDKs work. Point them at Hexel Studio and use a Hexel Studio API key, not an E2B key:

Python
import os
os.environ["E2B_API_URL"] = "https://api.hexelstudio.com/v1/sandbox/e2b"
os.environ["E2B_API_KEY"] = os.environ["HEXEL_API_KEY"]   # a Hexel Studio API key

from e2b import Sandbox
sbx = Sandbox.create("browser")   # its network comes from your egress policy

The workspace and environment come from the X-Workspace-Id and X-Environment-Id headers. Another organization's sandbox is always "not found", and lists show only your organization's sandboxes.

An agent governed by Titan calls the same API at https://api.hexelstudio.com/v1/titan/sandbox/e2b with its Titan runtime token as the bearer. It can create and manage its own sandboxes in its token's workspace and environment, but never change an egress policy or a grant.

Set the egress policy

One policy per scope: the organization, a workspace, or an environment of a workspace. The most specific policy that is set applies. X-Workspace-Id and X-Environment-Id choose the scope; send neither for the organization's.

Bash
curl -X PUT https://api.hexelstudio.com/v1/sandbox/egress-policy \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -H "X-Workspace-Id: $WORKSPACE_ID" \
  -H "Content-Type: application/json" \
  -d '{
    "allow_out": ["pypi.org", "*.pythonhosted.org", "github.com"],
    "allow_internet": false,
    "allowed_templates": ["browser"],
    "max_timeout_seconds": 3600
  }'
FieldMeaning
allow_outHosts (wildcards such as *.pythonhosted.org allowed) and CIDR ranges a sandbox may reach.
deny_outHosts and ranges denied.
allow_internetfalse (the default) denies everything except allow_out. true allows the internet except deny_out.
allow_public_traffictrue lets anyone reach the sandbox's URLs without its traffic token. Applies to sandboxes created after the change.
allowed_templatesTemplates a sandbox may be created from; empty means any.
max_timeout_secondsThe longest a sandbox may live, checked on create and on every request that extends it; 0 means the provider's own limit.
allowed_isolationIsolation kinds a sandbox may run with; empty means any.

Unknown fields are refused. The change reaches running sandboxes at once: the answer lists each one it was applied to, and paused sandboxes as deferred (applied when they resume).

Private address ranges, link-local addresses (cloud metadata) and the cloud provider's internal endpoints are always denied, and refused in any allow_out entry or grant. GET /egress-policy returns them as always_deny.

Method and pathWhat it doesPermission
GET /v1/sandbox/egress-policyThe policy set at this scope (policy, or null) and the one that applies (effective, with from: the scope it comes from, or default)sandbox:policy:read
GET /v1/sandbox/egress-policiesEvery policy of the organizationsandbox:policy:read
PUT /v1/sandbox/egress-policySet the policy at this scopesandbox:policy:write
DELETE /v1/sandbox/egress-policyRemove it; the next policy up appliessandbox:policy:write

Open one destination for one sandbox

An administrator can let one running sandbox reach one more destination, for a while or until revoked:

Bash
curl -X POST https://api.hexelstudio.com/v1/sandbox/sandboxes/$SANDBOX_ID/egress-grants \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"destination": "api.github.com", "reason": "clone the repository", "expires_in_seconds": 3600}'

The grant (grant_id, destination, reason, granted_by, expires_at) applies to that sandbox only; expires_in_seconds: 0 means no expiry. List a sandbox's grants with GET .../egress-grants (sandbox:egress:read) and revoke one with DELETE .../egress-grants/{grant_id} (sandbox:egress:grant). An agent can't change a sandbox's network directly: the E2B PUT /sandboxes/{id}/network call is always refused.

From the CLI, hexel sandbox list lists running sandboxes, hexel sandbox get <SANDBOX_ID> shows one with its network and egress grants, and hexel sandbox kill <SANDBOX_ID> ends it.

Titan and sandboxes

  • Kill. When you kill an agent, a session or a wider scope with the Kill switch, sandboxes that the agent created with its runtime token stop serving it: its next request is refused with 403.
  • Agents asking for a destination. Titan has a capability for an agent to ask for one more destination, sandbox.egress.allow, which always needs a person's approval. It is not turned on for Titan Cloud yet; until it is, an administrator adds the grant as above.

Every policy change, grant and refusal is recorded in the sandbox audit trail (GET /v1/sandbox/audit-events, permission sandbox:audit:read).