Skip to main content
Guide

Control egress

ACA sandboxes are designed to run untrusted code. Egress policies restrict outbound traffic and let the egress proxy inject secret-backed headers without exposing the resolved secret to the sandbox.

warning

Sandboxes have unrestricted outbound access when no egress policy is configured. Egress policies are opt-in.

How to deny all outbound traffic​

You can define a deny policy that blocks outbound calls unless a rule allows them. Begin with deny, then add the smallest host list your workload needs.

  1. Open the sandbox from Sandbox groups > your group > Sandboxes.
  2. From the sandbox details, select Egress policy.
  3. Set Default action to Deny.
  4. Set Traffic inspection to Full.
  5. Add *.github.com with action Allow.
  6. Select Save. Wait a few seconds before you test the policy.
aca sandbox create --disk ubuntu --label name=demo-egress
aca sandbox egress set -l name=demo-egress --default Deny \
--rule "*.github.com:Allow" \
--traffic-inspection Full
aca sandbox egress show -l name=demo-egress

For simple host rules, use --rule "<pattern>:<Action>". The action is Allow or Deny.

aca sandbox egress set -l name=demo-egress --default Deny \
--rule "*.github.com:Allow" \
--rule "example.com:Deny" \
--traffic-inspection Full

You can also set the policy when you create a sandbox:

aca sandbox create --disk ubuntu \
--label name=demo-egress \
--egress-default Deny \
--egress-rule "*.github.com:Allow" \
--traffic-inspection Full

How to allow all outbound traffic​

You can define an allow policy for sandboxes that need normal outbound access, with deny rules for specific destinations.

aca sandbox create --disk ubuntu \
--label name=demo-egress-allow \
--egress-default Allow \
--egress-rule "example.com:Deny" \
--traffic-inspection Full

For an existing sandbox:

aca sandbox egress set -l name=demo-egress --default Allow \
--rule "example.com:Deny" \
--traffic-inspection Full

Inject a secret into an outbound request​

Reference a sandbox-group secret from an advanced Transform header rule. The secret stays outside the sandbox at runtime: the egress proxy injects it into matching outbound requests after they leave the sandbox, so code running in the sandbox never has the value.

defaultAction: Deny
trafficInspection: Full
rules:
- name: inject-model-credential
match:
host: "api.example.com"
path: "/v1/*"
methods: [POST]
scheme: https
action:
type: Transform
headers:
- operation: Set
name: Authorization
valueRef:
secretRef:
secretId: model-credentials
secretKey: API_KEY
format: "Bearer {value}"

A transform can also inject a managed identity access token via a managedIdentityRef.

Control traffic inspection​

Traffic inspection controls how much request information the egress policy can evaluate. Choose the lowest inspection level that supports your policy rules, and verify exact transport behavior in the current product or CLI help.

ModeUse when
FullYou need the policy to evaluate host rules, path or method matches, rewrites, or header transforms.
PartialYou need limited inspection for selected policy behaviors.
NoneYou do not need egress policy inspection for this sandbox.
aca sandbox egress set -l name=demo-egress \
--default Deny \
--rule "*.github.com:Allow" \
--traffic-inspection Full

Create-time policy flags support the same inspection setting:

aca sandbox create --disk ubuntu \
--label name=demo-egress \
--egress-default Deny \
--egress-rule "*.github.com:Allow" \
--traffic-inspection Full

Use a policy file for advanced rules​

Use policy files for path or method matches, rewrites, transforms, and header operations.

Supported rule fields:

FieldSupported values
match.hostRequired host name or wildcard pattern.
match.pathOptional path match, such as /headers.
match.methodsOptional HTTP methods, such as [GET, POST].
match.schemehttp, https, or any. Controls which request schemes match the rule.
action.typeAllow, Deny, Rewrite, or Transform.
action.hostRewrite target host. Only valid when action.type is Rewrite.
action.pathRewrite target path. Only valid when action.type is Rewrite.
action.schemeRewrite destination scheme, such as https. Only valid when action.type is Rewrite.
action.headersHeader mutations. Valid when action.type is Transform or Rewrite.
headers[].operationSet, Insert, or Remove. Only valid inside action.headers.
aca sandbox egress init > egress.yaml
aca sandbox egress schema > egress.schema.json
aca sandbox egress apply -l name=demo-egress --file egress.yaml
aca sandbox egress export -l name=demo-egress > current-egress.yaml

Example advanced policy:

defaultAction: Deny
trafficInspection: Full
rules:
- name: inject-test-header
match:
host: "httpbin.org"
path: "/headers"
methods: [GET]
action:
type: Transform
headers:
- operation: Set
name: X-Test-Header
value: egress-test

Rules are evaluated in order. The first matching rule wins.

Match rules by scheme​

match.scheme controls whether a rule matches http, https, or any.

When match.scheme is omitted, the default depends on the rule:

RuleDefault scheme
Allow, Transform, or Rewritehttps
Denyany

With HTTPS, the egress proxy can authenticate the requested host through the remote server's TLS certificate. Plain HTTP has no certificate that binds the sandbox-controlled Host header to the destination IP. Untrusted code could connect to a different IP while presenting an allowlisted host, so positive rules exclude HTTP by default while deny rules cover both schemes.

Setting match.scheme to http or any on a positive rule opts into this risk. Use it only when another mechanism establishes trust in the destination.

defaultAction: Deny
trafficInspection: Full
rules:
- name: allow-api-https
match:
host: "api.example.com"
scheme: https
action:
type: Allow
- name: deny-example-all-schemes
match:
host: "example.com"
scheme: any
action:
type: Deny

Delegate decisions to a webhook​

Replace a rule's static action with a hookRef to have an external endpoint decide, transform, or rewrite the request at runtime — for tenant-specific authorization, runtime token minting, or dynamic upstream routing. See Make dynamic egress decisions with a webhook.

Verify allowed and blocked hosts​

After the policy propagates, test from inside the sandbox. An allowed host should return a normal HTTP status. A blocked host should fail or return a non-200 status.

  1. Open the sandbox, then select Connect > Interactive shell.
  2. Run curl https://example.com to test a blocked host.
  3. Run curl https://api.github.com to test an allowed host.
  4. Select Network audit to review the recorded decisions.
aca sandbox exec -l name=demo-egress -c \
"curl -fsS -o /dev/null -w 'HTTP %{http_code}\n' --max-time 8 https://example.com" || echo "blocked"

aca sandbox exec -l name=demo-egress -c \
"curl -sS -o /dev/null -w 'HTTP %{http_code}\n' --max-time 8 https://api.github.com"

Audit decisions​

The audit view shows outbound connection attempts and each host policy decision.

  1. Open the sandbox, then select Network audit.
  2. Use the host filter to find a domain.
  3. Review the decision, timestamp, and target host for each entry.
  4. Update Egress policy if the sandbox needs another allowed host.
aca sandbox egress decisions -l name=demo-egress
aca sandbox egress decisions -l name=demo-egress -o json

Use -o json in scripts. The JSON output separates allowed and denied decisions.