Skip to main content
Guide

Control egress

Choose how outbound traffic is allowed or denied, configure inspection, and audit policy decisions from the sandbox. If no egress policy is specified, the sandbox has unrestricted outbound access. Egress policies are opt-in.

Deny outbound traffic by default

A default deny policy 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

Allow outbound traffic by default

Use an allow-by-default 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

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].
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 target scheme, such as https. Only valid when action.type is Rewrite.
action.headersHeader mutations. Valid when action.type is Transform or Rewrite.
headers[].operationSet, Append, 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: Append
name: X-Test-Header
value: egress-test

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

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.