How to Restrict a MicroVM's Outbound Traffic
Last verified 16 Nov 2026
DigitalOcean MicroVMs are lightweight virtual machines that run a container image in an isolated kernel, pause automatically when idle, and resume on the next request with memory, files, and processes intact.
By default, a DigitalOcean MicroVM with public networking can connect to any destination on the internet. An outbound policy limits a MicroVM to the domains and IP addresses you allow, which is useful when the MicroVM runs code you do not fully trust, such as code written by an AI agent.
An outbound policy can also hold credentials, such as API keys. The platform adds a credential to requests the MicroVM sends to a matching host, so the secret never exists inside the MicroVM, and code running there cannot read or leak it.
You set the outbound policy when you create the MicroVM, and you cannot change it afterward. For how outbound policies work, including which protocols they allow, see MicroVM Networking and Access.
Prerequisites
- Public networking. Outbound policies are not available with VPC networking, where the VPC network’s own controls apply.
- An application that sends HTTP and HTTPS requests through the proxy set in the
HTTP_PROXYandHTTPS_PROXYenvironment variables. Most HTTP clients and command-line tools do this by default. - For
doctl,doctlv2.1.0 or later.doctlcan set rules but not credentials. - For credentials, an application whose HTTPS client trusts the platform’s certificate authority. See Use Credentials with HTTPS.
Restrict Outbound Traffic Using the Control Panel
When you create a MicroVM from a container image, select Public under Networking. Then, under Outbound network (egress), turn on Restrict outbound traffic.
In Add a destination, enter a destination and press Enter. You can also paste a list. Each destination is one of the following:
- An exact hostname, such as
api.example.com. - A wildcard, such as
*.example.com, which matches subdomains ofexample.combut notexample.comitself. - An exact IPv4 address, such as
203.0.113.5.
Your destinations appear under Allowed destinations. Everything else is blocked. If you add no destinations, every outbound connection is blocked.
To attach a credential to an allowed host, open Add credentials for allowed hosts, then click Add credential and fill in the following fields:
- Destination URL: An
https://URL with an exact hostname, such ashttps://api.example.com/v1/. The credential is added only to requests whose path starts with the path in this URL. The host must also be in your allowed destinations. If it is not, click Add to allowed destinations. - Scheme: Bearer sends
Authorization: Bearer <secret>. Raw sends the secret as the wholeAuthorizationheader value. - Secret: The API key or token. The secret is encrypted and stored once, and is never shown again.
Finish creating the MicroVM as usual. The MicroVM’s Overview tab shows its outbound rules under Outbound network, along with the scheme, host, and path of each credential. Secret values are never shown.
Restrict Outbound Traffic Using doctl
Add --egress-allow to doctl compute microvm create once for each destination:
doctl compute microvm create example-microvm \
--oci-ref docker.io/library/python:3.13-slim \
--region mkc1 \
--cpu 1 \
--memory 2048 \
--egress-allow api.example.com \
--egress-allow '*.example.org' \
--egress-allow 203.0.113.5Quote wildcards so your shell does not expand them. Any destination not listed is denied. To allow every destination while still routing traffic through the proxy, add --egress-default-action allow.
doctl cannot set credentials. To attach credentials, use the Control Panel or the API.
Restrict Outbound Traffic Using the API
Add egress_policy to the POST /v2/microvms request:
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
-d '{
"name": "example-microvm",
"region": "mkc1",
"size": {"cpu": 1, "memory": 2048},
"source": {"oci_ref": "docker.io/library/python:3.13-slim"},
"egress_policy": {
"default_action": "deny",
"rules": [
{"domain": "api.example.com"},
{"domain": "*.example.org"},
{"ip": "203.0.113.5"}
],
"credentials": [
{
"host": "api.example.com",
"path_prefix": "/v1",
"scheme": "bearer",
"secret": "<your-api-key>"
}
]
}
}' \
"https://api.digitalocean.com/v2/microvms"egress_policy has the following fields:
default_action: What happens to a destination that no rule matches.denyblocks it and is the default.allowlets it through.rules: Up to 50 destinations. Set exactly one ofdomain, which takes an exact hostname or a wildcard such as*.example.com, orip, which takes an exact IPv4 address.credentials: Up to 16 credentials. Each has the following fields:host: An exact hostname. A rule must allow it, ordefault_actionmust beallow.path_prefix: Optional. Only requests whose path starts with this prefix get the credential. Must start with/. Defaults to every path.scheme:bearer, the default, sendsBearer <secret>.rawsends the secret as is.secret: The credential, up to 8192 characters. It is stored in a secrets vault and never returned by the API.
The response includes egress_policy with your rules and default action. Credentials are returned without their secrets.
Credentials are available only in MKC1, and only for MicroVMs you create from a container image. A MicroVM you create from a checkpoint inherits the checkpoint’s credentials, and a request that sets credentials with source.checkpoint_id fails.
Use Credentials with HTTPS
To add a credential to an HTTPS request, the platform decrypts the request, adds the Authorization header, and encrypts it again with a certificate from the platform’s own certificate authority (CA). Do not set the Authorization header in your code for a host that has a credential. The platform sets it.
For your application to accept the platform’s certificate, it must trust the platform CA. The platform mounts the CA into the container in two forms:
/etc/ssl/certs/microvm-ca-bundle.crt: The system CA bundle with the platform CA added. TheSSL_CERT_FILE,CURL_CA_BUNDLE,REQUESTS_CA_BUNDLE,GIT_SSL_CAINFO,AWS_CA_BUNDLE, andDENO_CERTenvironment variables point to it./etc/ssl/certs/microvm-interception-ca.pem: The platform CA alone. TheNODE_EXTRA_CA_CERTSenvironment variable points to it.
Tools and runtimes that read these variables, such as curl, Python requests, Node.js, Git, and the AWS SDKs, trust the platform CA automatically. Runtimes that do not read them, such as the Java virtual machine, need you to import the CA yourself, for example into the Java trust store. Clients that pin certificates fail for hosts with credentials.
What a Blocked Request Looks Like
When a request goes to a destination the policy does not allow, an HTTP request gets an HTTP 403 response from the proxy, and an HTTPS connection is closed during the TLS handshake. Connections that do not use HTTP or HTTPS, such as SSH, database connections, and raw TCP or UDP, fail even for allowed destinations.
For help with blocked requests and credential errors, see MicroVMs Troubleshooting.