Skip to main content
Guide

Control egress

Choose how outbound traffic is allowed or denied, configure inspection, and audit policy decisions from the sandbox.

Deny outbound traffic by default

A default deny policy blocks outbound calls unless a rule allows them. Start 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

Use --rule "<pattern>:<Action>" for simple host rules. 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

Alternatively, 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 the egress proxy evaluates outbound TLS traffic. Choose the lowest inspection level that supports the policy rules you need.

ModeUse when
FullYou need egress enforcement, including default deny, deny rules, path or method matches, rewrites, or header transforms. This mode also blocks non-HTTP TCP and UDP traffic, except Azure DNS.
PartialYou only need rewrites or transforms for selected HTTPS hosts. Other HTTPS traffic passes through without request inspection. Deny rules are not supported in this mode.
NoneYou do not need the egress proxy for this sandbox. Traffic bypasses proxy inspection and egress policy enforcement.
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, 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: Insert
name: X-Test-Header
value: egress-test

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

Verify allowed and blocked hosts

Test from inside the sandbox after the policy has propagated. 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 the policy decision for each host.

  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

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