OutboundPolicy
class OutboundPolicy(object)Routes that control where outbound network traffic from a Sandbox goes.
A policy is an ordered list of OutboundRoutes. Each outbound connection is
handled by the first route that matches it, and goes to its original
destination. The last route must be OutboundRoute.any(), which matches
everything no earlier route matched and either lets it through or, with
.block(), blocks it.
Usage
import modal
secret = modal.Secret.from_name("api-token")
policy = modal.OutboundPolicy(
allow_tls_decryption=True,
routes=[
# Inject a secret-backed header into HTTPS requests.
modal.OutboundRoute.https(
domains=["api.example.com"],
header_replacements=[{"secret": secret, "headers": {"Authorization": "Bearer $API_TOKEN"}}],
),
# Allow TLS connections to these domains.
modal.OutboundRoute.tls(domains=["github.com", "*.github.com", "pypi.org"]),
# Allow all traffic to a CIDR range.
modal.OutboundRoute.ip(cidrs=["203.0.113.0/24"]),
# Block everything else.
modal.OutboundRoute.any().block(),
],
)
sb = modal.Sandbox.create(app=app, outbound_policy=policy)__init__(self, *, allow_tls_decryption=False, routes)Create an outbound policy.
Parameters