# Egress and credentials

> How a sandbox reaches the internet: default deny, egress rules, the egress proxy, secrets bound to hosts, and the tokens that act for your bucket.

Source: https://docs.compute.dev.ddcdragon.com/concepts/egress-and-credentials/

A sandbox reaches nothing by default. It reaches only the hosts its egress rules allow, through the cluster's egress
proxy, and the proxy adds the credentials those rules name, so a credential never enters the sandbox.

## The egress proxy

Every program in a sandbox that honours `HTTPS_PROXY` sends its requests to the egress proxy (the sandbox has no other
route out, and no DNS of its own). For each request the proxy:

1. refuses a host that no rule names, at the start of the connection (`403`, logged `host not in the sandbox's
   allow-list`);
2. refuses private and cluster addresses, whatever the rules say, and connects to the address it resolved itself;
3. for HTTPS, answers the sandbox's TLS with a certificate for the host signed by the cluster's egress CA, which the
   sandbox trusts (see [Inside a sandbox](https://docs.compute.dev.ddcdragon.com/concepts/sandboxes/#inside-a-sandbox)), and reads each request inside;
4. matches the method and path against the sandbox's rules, in order, and refuses a request no rule allows (`403`);
5. removes `Authorization`, `Proxy-Authorization`, `X-Api-Key`, `X-Auth-Token`, `Cookie`, `Forwarded` and
   `X-Forwarded-For` from the request, then sets the header of the secret the matching rule names, if it names one
   and the secret is bound to the host;
6. sends the request to the real host over TLS it verifies, streams the answer back, and writes an egress log entry.

Only HTTPS on port 443 and plain HTTP on port 80 are forwarded. Whatever the rules say, the proxy never forwards
`TRACE` or `TRACK` (`405`), a `CONNECT` sent inside a tunnel (`405`), or a protocol upgrade such as a WebSocket
handshake (`501`), and it refuses a path with `.` or `..` segments.

## Egress rules

A rule is `host[:METHODS[:path_prefix[:credential]]]`, as the CLI writes it, or `cere.Allow(host, methods,
path_prefix=, credential=)` in the SDK:

| Part | Meaning |
| --- | --- |
| `host` | An exact host name, or `*.example.com` for any name under `example.com` (not `example.com` itself). |
| `METHODS` | Upper-case methods, comma-separated, or `*`. The CLI and the SDK default to `GET`. |
| `path_prefix` | Optional. Matched on whole path segments: `/repos/org/app` admits `/repos/org/app` and `/repos/org/app/...`, not `/repos/org/app-private`. A prefix ending in `/` admits whatever starts with it. |
| `credential` | Optional. The name of a secret in your bucket, which the proxy adds to the requests this rule allows. |

A sandbox has up to 64 rules. You give them when you create it, and you can change them while it runs: the proxy
applies a change from the sandbox's next request, also inside a connection that is already open, so a host you remove
is refused from then on.

## Secrets

A secret is a request header (usually `Authorization`) and its value, stored in your bucket and held encrypted by the
egress proxy. It is write-only: no command, SDK call or API returns its value, and it is never logged.

Each secret is bound to the hosts it may be sent to (up to 32; `*.example.com` stands for exactly one more label). The
proxy sets it only on requests to those hosts, and a sandbox whose rule names it for any other host is refused when it
is created (`400 credential_not_bound`). So code in a sandbox cannot send your secret to a host of its choosing. A
program in the sandbox that needs a key to start may hold a placeholder: the proxy removes the credential headers a
sandbox sends (step 5 above) and sets the secret instead, so a credential reaches a host only as a secret a rule names.

If you delete a secret, a running sandbox whose rules name it gets `502 credential missing` on that host.

## Tokens and what they grant

Three kinds of token act for your bucket. Each grants COMPUTE on that one bucket: create and use sandboxes, store
secrets, read the egress log and usage, and call the inference API, all billed to the bucket. None can be revoked;
each expires.

| Token | Where it comes from | Lifetime |
| --- | --- | --- |
| Your login | `cere login`: the bucket owner's wallet approves it in the Developer Console, as a grant to a key the CLI makes on your machine. The grant is useless without that key. | 1, 7 or 30 days |
| An access token | Developer Console > Access tokens, for CI. | 1, 7 or 30 days |
| An inference API key | Developer Console > Inference > API keys, for the inference API. The same kind of token as an access token. | 7, 30 or 90 days |

`cere secret set <name> --from-login` stores the token you are signed in with as a secret, `Authorization: Bearer
<token>`, bound to the cluster's inference gateway. That gateway takes it as the model key for your bucket, which is
how the example agents reach their model with no other key. It stops working when your login expires; store it
again after the next `cere login`. Because the token grants COMPUTE on your bucket, bind such a secret only to the
cluster's own gateways, as `--from-login` does by default.

## The egress log

The proxy logs every request a sandbox makes, allowed or refused, and every change to a sandbox's rules (decision
`policy`). Paths are logged without their query string, and credentials by name only.

```sh
cere egress log --limit 5
```

```
TIME                  SANDBOX                        DECISION  METHOD   HOST         PATH  STATUS  CREDENTIAL  DOWN   MS  REASON
2026-11-25T09:00:57Z  sb-01m88yzdzw0tr5s8jjefmd7vmy  denied    CONNECT  example.com  -     403     -           0 B    -   host not in the sandbox's allow-list
2026-11-25T09:00:56Z  sb-01m88yzdzw0tr5s8jjefmd7vmy  policy    GET      example.com  -     -       -           0 B    -   rule removed
2026-11-25T09:00:55Z  sb-01m88yzdzw0tr5s8jjefmd7vmy  allowed   GET      example.com  /     200     -           577 B  76  -
2026-11-25T09:00:55Z  sb-01m88yzdzw0tr5s8jjefmd7vmy  policy    GET      example.com  -     -       -           0 B    -   rule added
2026-11-25T09:00:54Z  sb-01m88yzdzw0tr5s8jjefmd7vmy  denied    CONNECT  example.com  -     403     -           0 B    -   host not in the sandbox's allow-list
(the newest 5 entries; there are more: raise --limit, or --all for every one)
```

## Limits

| | Limit |
| --- | --- |
| Rules per sandbox | 64 |
| Requests per sandbox | 600 a minute, in bursts of up to 100 |
| Open connections per sandbox | 32 |
| Secret name | Lower-case letters, digits and `-`, not starting with `-`; up to 63 characters |
| Secret value | 8 KiB |
| Hosts per secret | 32 |

## Related

- [Next: Agents](https://docs.compute.dev.ddcdragon.com/concepts/agents/)
- [Guide: Egress and secrets](https://docs.compute.dev.ddcdragon.com/guides/egress-and-secrets/)
- [Signing in](https://docs.compute.dev.ddcdragon.com/guides/signing-in/)
- [Sandboxes](https://docs.compute.dev.ddcdragon.com/concepts/sandboxes/)
