kojo-proxy

kojo-proxy is the egress proxy of the k8s, e2b and docker drivers. It is part of the kojo binary, in internal/proxy. The sbx driver uses sbx’s own proxy instead, with the same allowlist and credentials. This page is for whoever deploys kōjō with one of those drivers: what the proxy lets through, how a credential reaches a forge, and how to run the proxy.

How a sandbox reaches the network

kojo-proxy is an HTTP forward proxy. A sandbox has no other route out: the Kubernetes network policy, the E2B-compatible service’s firewall or the internal Docker network lets it open connections to the proxy and to nothing else.

Each sandbox gets its own proxy username (the sandbox ID) and a random token. The driver sets them in the proxy URL of every command it runs:

Variable Value
HTTP_PROXY, HTTPS_PROXY, http_proxy, https_proxy http://<sandbox ID>:<token>@<proxy host>:<port>
GIT_HTTP_PROXY_AUTHMETHOD basic, so git sends the token with its first request; by default it first asks without it, which the proxy refuses and records
SSL_CERT_FILE, GIT_SSL_CAINFO, CURL_CA_BUNDLE, REQUESTS_CA_BUNDLE, NODE_EXTRA_CA_CERTS A CA bundle that includes the proxy’s CA
KOJO_CRED_<NAME> The placeholder of each credential, for example KOJO_CRED_GITHUB

The token is not a credential for anything else. It only selects that sandbox’s policy on the proxy.

For every request the proxy decides:

Decision When Answer to the sandbox
allowed The host and port are on the sandbox’s allowlist The request is forwarded or tunneled
denied_host The host is not on the allowlist, or not for that port HTTP 403
unauthenticated No proxy credentials, wrong ones, or a sandbox whose policy is gone HTTP 407 (403 inside an already open intercepted connection)
blocked_address The host is allowlisted but resolves to a non-public address HTTP 403
too_many_connections The sandbox already has max_conns_per_sandbox connections open through the proxy HTTP 429

A sandbox with no policy, or with an empty allowlist, reaches nothing.

What the proxy does with an allowed request depends on the host:

  • A host with a credential: the proxy terminates TLS with a certificate signed by its own CA, sets the credential header and forwards the request over TLS to the real host. The sandbox trusts the CA through the bundle above.
  • Any other allowlisted host: CONNECT gets a blind tunnel. The proxy cannot read the stream and injects nothing.
  • Plain http:// requests are forwarded, with the credential header set when the host has one.

A replaced or deleted policy takes effect on the next request, also on connections that are already open.

One sandbox cannot use up the proxy, which in embedded mode is the kojo serve process. Each sandbox may have at most sandbox.proxy.max_conns_per_sandbox (default 64) connections open through it at once: tunnels, intercepted connections and plain HTTP requests in flight. One more gets HTTP 429 until one closes; other sandboxes are not affected. A tunnel through which nothing has gone either way for sandbox.proxy.idle_timeout (default 5 minutes) is closed at both ends; bytes going one way, such as a long download, keep it open. A sandbox’s keep-alive connection to the proxy is closed after the same time without a request, and a client that has not sent a request’s headers within 30 seconds is disconnected.

Embedded and remote mode

The proxy runs in one of two modes:

  • embedded: inside the kojo serve process. The default for the docker and e2b drivers. With e2b it needs sandbox.proxy.advertise_url, because the sandboxes are elsewhere.
  • remote: its own process, started with kojo proxy. The default for the k8s driver, where it is its own Deployment. kōjō drives it through an admin API.
Key Default Meaning
sandbox.proxy.mode embedded; remote for k8s Where the proxy runs.
sandbox.proxy.listen :3128 Address sandboxes connect to.
sandbox.proxy.advertise_url derived from the listener The proxy’s address as sandboxes see it: http://host:port, without a path or user.
sandbox.proxy.admin_listen :3129 Address of the admin API in kojo proxy.
sandbox.proxy.admin_url none The remote proxy’s admin API, as kōjō reaches it: one replica, or with admin_discovery: dns a name that resolves to every replica. In remote mode it or admin_urls is required.
sandbox.proxy.admin_discovery empty dns: every address the host of admin_url resolves to is a replica, resolved again every 5 seconds. See Several replicas.
sandbox.proxy.admin_urls none The admin APIs of several replicas at fixed addresses, instead of admin_url.
sandbox.proxy.admin_token none Bearer token of the admin API. Required in remote mode.
sandbox.proxy.sync_timeout 30s How long a new kojo proxy replica waits for a kōjō server to send it the policies before it reports ready anyway.
sandbox.proxy.ca_cert_file, ca_key_file none The CA that signs certificates for hosts with a credential. Set both or neither. Several replicas need both, read by every replica.
sandbox.proxy.private_hosts empty Hosts that may resolve to private addresses: a forge on a private network. See Private addresses.
sandbox.proxy.allow_private false Let sandboxes reach every allowlisted host on private addresses. Prefer private_hosts.
sandbox.proxy.upstream_ca_file none Extra root certificates (PEM) the proxy trusts when it connects to a host it injects credentials on: a forge with a private CA.
sandbox.proxy.max_conns_per_sandbox 64 Connections one sandbox may have open through the proxy at once; one more gets HTTP 429. At least 1.
sandbox.proxy.idle_timeout 5m How long a tunnel may carry nothing either way, and a keep-alive connection go without a request, before the proxy closes it. At least 1s.

When the CA files are set and missing, the proxy generates the CA (ECDSA P-256) and writes it: the certificate with mode 0644, the key with mode 0600. When neither is set, the CA lives in memory and is new on every start. The CA key never leaves the proxy process; sandboxes get the certificate only.

kojo proxy takes no flags of its own. It reads sandbox.proxy of the kojo.yaml given with -f and nothing else, so its file may hold that section alone, with no database URL or other credential of kōjō’s (the Helm chart gives it such a file, <fullname>-proxy-config). It needs admin_token, and refuses to start unless sandbox.proxy.mode is remote:

kojo proxy -f /etc/kojo/kojo.yaml

The admin API carries real credentials. Serve it on a network only kōjō reaches. Every route except /healthz and /readyz needs Authorization: Bearer <admin_token>.

Route What it does
PUT /v1/policies/{sandboxID} Create or replace a sandbox’s policy
PUT /v1/policies/{sandboxID}?set_at=<time> The same, recording <time> (RFC 3339), when kōjō set the policy, so that a restore from an earlier time does not replace it. kōjō sets every policy this way.
PUT /v1/policies/{sandboxID}?restore=<time> A policy kōjō sends again: after the proxy restarted, or to a replica that missed it. <time> is when kōjō set it. Answers 409 and changes nothing when the proxy holds a policy for the sandbox that was set later, or set without a time.
DELETE /v1/policies/{sandboxID} Forget a sandbox
GET /v1/endpoint The proxy’s address and CA certificate
GET /v1/instance The proxy’s instance ID: random, and new on every start
GET /v1/status instance, ready, synced, and policies: how many sandbox policies it holds
POST /v1/synced Body {"instance": "<id>"}: a kōjō server has sent this instance every policy it remembers and every delete it owed. 409 when the proxy is another instance.
GET /healthz Health check, no authentication
GET /readyz 200 once the proxy is ready for sandbox traffic, 503 before; no authentication. See Several replicas.

Every answer to an authenticated request also carries the instance ID, in the Kojo-Proxy-Instance header.

Several replicas

A proxy keeps the policies it was given in memory only, so with one replica a restart, a node drain or a crash cuts sandboxes off for a few seconds. Run several. Sandboxes still reach the proxy through one address (a Kubernetes Service, a load balancer), so a request can land on any replica, and every replica holds every policy:

  • Discovery. kōjō drives each replica through its own admin API. With admin_discovery: dns, every address the host of admin_url resolves to is a replica. kōjō resolves the name again every 5 seconds: a replica that appears is found, one that is gone is forgotten, and a failed lookup keeps the replicas it knows. On Kubernetes the name is a headless Service that publishes replicas before they are ready (publishNotReadyAddresses: true); the Helm chart creates it as <fullname>-proxy-admin. Replicas at fixed addresses go in admin_urls. One admin_url with a load balancer behind it does not work, because kōjō would reach one replica at a time: when one address answers with the instance IDs of several replicas, kōjō logs it at error level and kojo doctor fails.
  • Set. kōjō sends a policy to every replica that answered at its last contact, all at once. The call succeeds when at least one replica took it and none refused it. A replica that could not be reached is behind: kōjō sends it the policy as soon as it answers, as a restore with the time the policy was set, so it never replaces a newer one. Until then that replica keeps what it had: a request that lands there gets 407 for a new sandbox, or the previous policy of a sandbox whose policy was replaced. Failing the call instead would not take the policy back from the replicas that took it, and one replica that is down or rolling would fail every sandbox start.
  • Delete. kōjō sends a delete to every replica. A replica that misses it owes it: kōjō sends it again every 2 seconds until it lands, until the replica restarts (a new instance holds nothing) or until it is no longer discovered. Until then the deleted sandbox’s token still selects its policy on that replica. The call returns an error when no replica took the delete or one refused it.
  • Readiness. A new or restarted replica answers 503 on /readyz until a kōjō server has sent it every policy it remembers and every delete it owes, and has said so with POST /v1/synced. It then waits 10 more seconds, so that the other kōjō servers, which find a new replica within seconds of each other, send theirs, and turns ready. Kubernetes sends no sandbox traffic to a replica that is not ready. A replica that no kōjō server syncs within sync_timeout (default 30s) after it started turns ready anyway, so that a rollout finishes while kōjō is not running. It holds only what reached it, and refuses every sandbox it does not know (407).
  • CA. A sandbox trusts one CA and its requests land on any replica, so every replica must sign with the same CA. kōjō refuses several replicas (admin_discovery: dns, or more than one entry in admin_urls) without ca_cert_file and ca_key_file, and refuses to start a sandbox while two replicas advertise different CAs. The Helm chart mounts one Secret in every replica.

The replicas only hold what kōjō could deliver to them. A replica that sandboxes can reach but kōjō cannot keeps its policies as they were until kōjō reaches it again: a new sandbox gets 407 there, and a policy replaced or deleted in the meantime still applies there. kojo doctor names such a replica.

After a proxy restart

In remote mode a proxy replica can restart while kojo serve keeps running: a rescheduled pod, a crash. The new instance holds no policies, so a running sandbox’s requests that reach it get 407 until kōjō sends its policy again, which takes a few seconds. With several replicas the restarted one is not ready until then, and requests go to the others.

  • Each kōjō server remembers, in its own memory, the last policy it set for each sandbox, and forgets it when it destroys the sandbox. Nothing is written to disk or to the database.
  • kōjō asks every replica for its status every 2 seconds, and reads the instance ID from the header of every other admin API answer. A new ID at an address means that replica restarted.
  • kōjō then sends each remembered policy again, to each replica that lacks it, up to 8 policies at a time. It resolves the credentials again first, once for all the replicas, so a short-lived one such as a GitHub installation token is fresh. A sandbox the driver no longer finds is forgotten instead. When a credential cannot be resolved, kōjō sends the values it has that have not expired; it never sends an expired one.
  • With several kōjō replicas, each sends the policies it set. When two remember the same sandbox, because its session moved from one to the other, the proxy keeps the one set last and the other kōjō replica forgets it.

Connections a sandbox had open through the old instance are gone; its next request opens a new one. The sandbox only trusts the new instance if the CA survived the restart: set ca_cert_file and ca_key_file to files that persist. The Helm chart keeps the CA in a Secret.

A policy comes back only from the kōjō server that set it. If that server restarted too, the policy is applied again when the session resumes and runs its next skill. In embedded mode the proxy and kōjō always restart together, so this is the only path.

Egress allowlists

A sandbox’s allowlist is built from three places.

1. The skill’s kit. kit.yaml lists the hosts the skill needs under egress.allow. Everything else is denied. An entry is a hostname or a *.domain pattern, for ports 443 and 80, or either with a port, registry.example.com:5000, for that port only. The kit format is on the kit.yaml page.

image: ghcr.io/example/toolchain-go:1.25
resources: { cpu: "4", memory: 8Gi, disk: 40Gi }
needs_docker: true
egress:
  allow:
    - proxy.golang.org
    - sum.golang.org
    - api.github.com
credentials:
  - name: github
    hosts: [api.github.com]
setup:
  - go mod download

2. The runtime egress limits. The runtime config object settings/egress bounds what a kit may ask for. Only an admin edits it, in the dashboard or with kojo config apply; see Runtime config objects. A repository can have its own, which replaces the org’s for that repository.

version: 1
objects:
  - scope: org
    object: settings/egress
    content:
      allowed_hosts:
        - proxy.golang.org
        - sum.golang.org
        - registry.npmjs.org
        - "*.example.com"
        - github.com
        - api.github.com
      allowed_credentials:
        - github

A new install starts with the Go, npm, PyPI, crates.io, Maven Central and RubyGems registry hosts, the vulnerability databases vuln.go.dev and api.osv.dev, and the hosts of the configured forges, with the configured forges as allowed credentials. That covers every host a built-in kit allows, so a built-in skill can be customised without widening the limits first.

3. The session’s repository. kōjō adds the host the repository is cloned from, and the forge’s clone credential for it, to every sandbox of the session. A kit does not list the forge. A forge whose base_url names a port other than 443 and 80 (the dev stack’s Forgejo on 3000) is added with that port, and so is its credential.

How they combine:

  • The limits never add a host to a sandbox. A sandbox gets its kit’s hosts plus the clone host, and nothing more.
  • Every host in a kit must be covered by allowed_hosts: listed exactly, or inside an approved wildcard, for the same port. A wildcard in a kit is only covered by the same or a broader wildcard. An entry without a port is for 443 and 80, so it does not cover host:8443, and host:443 does not cover host. Every credential in a kit must be in allowed_credentials.
  • A repository or org skill whose kit asks for more is dropped when the session resolves its skills, and reported as a problem. A skill draft that asks for more is refused. The dashboard shows the same errors when you validate a draft.
  • Built-in skills are exempt from the limits: their kits are part of the release.
  • The allowlist is the current skill’s. Before each skill runs, the sandbox is narrowed to that skill’s hosts.

In kojo-proxy, *.example.com matches any subdomain at any depth and does not match example.com itself. A bare * is refused everywhere.

Ports are part of an entry. example.com allows ports 443 and 80, which is what https:// and http:// URLs use; example.com:8443 allows port 8443 and no other. A port is a number from 1 to 65535. This applies to CONNECT and to plain http:// requests, and a refusal names the host and port it refused. Before this rule an entry allowed every port of its host: a kit that reached another port by name alone now has to name the port. On sbx an entry without a port still allows every port, because sbx’s own proxy enforces the allowlist (see sbx).

Credential injection

A kit never carries a secret. It names a credential, and optionally the hosts to use it on. Each host must also be in the kit’s egress.allow. A credential is set only on the ports its own host entry allows: one for forge.example is not set on forge.example:8443, even when the allowlist names that port.

A name resolves only when it is the forge of the session’s own repository (github, gitlab, forgejo or bitbucket), and only to that repository’s clone credentials. Any other name fails when the sandbox is created.

Credential Hosts Header the proxy sets Lifetime and scope
github the git host, and the API host when it differs (github.com, api.github.com) Authorization (Basic on the git host, Bearer on the API host) A GitHub App installation token for that one repository with contents: read and metadata: read. Short-lived.
gitlab the GitLab host Authorization (Basic) The configured token. Not short-lived, and the token itself can write.
forgejo the Forgejo host Authorization (Basic) The configured token. Not short-lived, and the token itself can write.
bitbucket bitbucket.org and api.bitbucket.org Authorization (Basic on bitbucket.org, Bearer on the API host) The configured API token. Not short-lived, and the token itself can write.

Every forge credential is read-only at kojo-proxy, whatever the token behind it could do. Each forge marks the host it serves git from as a git host: github.com or the Enterprise Server host, the GitLab and Forgejo hosts, bitbucket.org. api.github.com and api.bitbucket.org serve only an API. On a git host the proxy sets the credential on git’s fetch and nothing else; on an API-only host, on reads:

Request Git host API-only host
GET …/info/refs?service=git-upload-pack, git’s ref discovery: see below yes yes
POST …/git-upload-pack, git’s fetch and clone: see below yes no
Any other GET, HEAD or OPTIONS: the API’s reads, web pages, archives, info/refs for a push, Git LFS no yes, except the token paths below
GET …/jwt/auth (GitLab), GET …/v2/token (Forgejo, Gitea), GET …/conan/<version>/users/authenticate (GitLab, Forgejo, Gitea), GET …/runners/registration-token (Forgejo, Gitea) no no
POST to /git-receive-pack (git push) no no
Any other POST, and every PUT, PATCH or DELETE no no

git’s requests are matched exactly. The ref discovery’s query must be exactly service=git-upload-pack and its path must end in /info/refs; the fetch’s last segment must be git-upload-pack. Each must come after at least one other segment, with or without .git before it: Go modules fetched through GOPRIVATE, Cargo and pip fetch from URLs without .git. The path must also be clean (no //, no . or .. segment, no trailing slash), carry no percent-escapes, and not be under a forge’s API route: a segment api followed by a version (v1, v4, 1.0, 2.0: digits with an optional v before them and an optional . and digits after), graphql, forgejo or packages, or a segment !api, in any case. bitbucket.org serves its API at both /api/2.0 and /!api/2.0. A suffix alone is not enough: GitLab’s POST /api/v4/projects/:id/repository/files/:path and Forgejo’s POST /api/v1/repos/:owner/:repo/contents/:path create a file at a path the caller chooses, and Bitbucket’s POST /2.0/repositories/:workspace/:slug (also bitbucket.org/api/2.0/…) creates a repository, so a path ending in git-upload-pack can be a write. A group named api below the top level (/acme/api/users.git) is not an API route, and fetches with the credential.

On a git host the API gets no credential at all, reads included, because the token behind a clone credential reads more than code there: GitLab answers a Maintainer’s GET /api/v4/projects/:id/variables with the project’s CI/CD variables and includes its runners token in GET /api/v4/projects/:id, and Forgejo answers an administrator’s GET /api/v1/repos/:owner/:repo/actions/variables and …/hooks with Actions variables and webhooks. A clone needs git’s fetch only: nothing kōjō runs in a sandbox reads a forge’s API, and kōjō does not clone with Git LFS, so LFS requests get no credential either.

A GitLab subgroup named like an API route. A fetch from a path such as /acme/api/v4/project.git, /acme/api/2.0/project.git or /acme/api/graphql/project.git (a subgroup api with a subgroup v1, v4, 2.0, graphql, packages or forgejo under it) goes out without the credential on kojo-proxy, and is refused by sbx. A public project still clones; a private one does not.

The token paths exchange the credential for a token that can write: GitLab’s GET /jwt/auth and Forgejo’s GET /v2/token for a container registry token, which can push when the request asks for that scope; GET …/conan/<version>/users/authenticate for a Conan registry token, which uploads packages; Forgejo’s and Gitea’s GET …/actions/runners/registration-token (repository, organization, user or instance) for a runner registration token, which Forgejo creates on that read. A runner registered with it is sent the repository’s jobs, each with a token that can push. None of them gets the credential, on either kind of host, in any case and with or without an extension on the last segment, so the forge’s registries cannot be used, and no runner registered, with the clone credential from a sandbox. On a git host the rule above leaves them out already; this check is a second line.

A request the rule leaves out still goes out, without the credential, and the forge answers it as an anonymous one. So on GitLab, Forgejo and Bitbucket the token is the configured one, but a sandbox behind kojo-proxy can only fetch with it: it cannot push, call a writing API or read the API on the git host.

On sbx. kojo-proxy is not used with the sbx driver: Docker Sandboxes’ own proxy sets the credential on every request to its host. The driver adds deny rules there that refuse, with a 403, everything but git’s fetch on a git host and every write on an API-only host (see Read-only credentials). GitHub’s token is also read-only by its own permissions on every driver.

A credential’s scope key in a kit is documentation only. Nothing enforces it.

How a placeholder becomes a real credential:

  1. The driver asks the core to resolve the kit’s credential names. The core holds the forge clients; nothing else sees a token.
  2. The driver hands the resolved values to the proxy, as part of the sandbox’s policy. They are never written to the sandbox, its environment or the cluster.
  3. Inside the sandbox, each credential is visible as a placeholder, kojo-placeholder-<name>, in the variable KOJO_CRED_<NAME>.
  4. On a request to one of the credential’s hosts, the proxy sets the header when the request has none, and replaces it when it carries the placeholder, as is or inside a Basic value (which is how git sends tokens). A header the sandbox filled with something else is left alone.
  5. Requests to any other host are never touched, so a placeholder sent elsewhere stays a placeholder.

The same steps for a git fetch and a git push from a sandbox behind kojo-proxy:

sequenceDiagram
    participant C as Core
    participant D as Driver
    participant P as kojo-proxy
    participant S as Sandbox
    participant F as Forge host
    C->>D: ApplyPolicy, before each skill
    D->>C: resolve the credential name
    C-->>D: clone credential, marked read-only
    D->>P: policy with the allowlist and the credential
    C->>D: Exec git fetch
    D->>S: run it with the proxy URL, the CA bundle and the placeholder
    S->>P: CONNECT to the forge host, as sandbox ID and token
    Note over P: The host is allowlisted and has a credential, so TLS ends at the proxy
    S->>P: GET info/refs?service=git-upload-pack, POST git-upload-pack
    P->>F: the same requests, with the credential header set
    F-->>S: the pack, back through the proxy
    S->>P: GET info/refs?service=git-receive-pack, a push
    P->>F: the same request, without the credential
    F-->>S: answered as an anonymous request

So git fetch over HTTPS works without any configuration in the sandbox, and a tool that insists on a token can be given the placeholder:

curl -H "Authorization: Bearer $KOJO_CRED_GITHUB" https://api.github.com/rate_limit

A credential with an expiry is no longer injected once it has expired. ApplyPolicy, which runs before every skill, resolves the credentials again, and so does kōjō when it sends a policy again after a proxy restart.

Private addresses

By default the proxy refuses to connect to loopback, link-local, private and other non-public addresses, also for an allowlisted name. It resolves the name itself, checks every address, and connects to an address it checked, so a name that resolves differently a moment later cannot get past it. A name that mixes public and private addresses is refused. This stops a sandbox from using the proxy to reach the cloud metadata service or the network kōjō runs in.

When your forge, or a registry, is on a private network, name it in sandbox.proxy.private_hosts (hostnames or *.domain patterns, without a port: the allowlist decides the ports). Those names may resolve to private addresses; every other allowlisted host still has to resolve to public ones, so an allowlisted name that someone points at your network gets nothing. A name there is reached only when a sandbox’s allowlist names it too, and the address checked is still the address connected to.

sandbox:
  proxy:
    private_hosts: [gitlab.corp.internal]

With the Helm chart, the value is proxy.privateHosts; the kind dev stack names its Forgejo, forgejo.kojo.svc.

sandbox.proxy.allow_private: true turns the check off for every allowlisted host; prefer private_hosts.

Metrics, logs and audit

Signal Where Content
kojo_proxy_requests_total{decision} kojo serve’s /metrics (server.metrics_listen), embedded mode only Counter of requests by decision: allowed, denied_host, unauthenticated, blocked_address, too_many_connections
kojo_proxy_policies_resent_total{replica} kojo serve’s /metrics (server.metrics_listen), remote mode only Counter of sandbox policies kōjō sent a replica again because it had restarted, was new, or had missed them. replica is the replica’s admin address.
Log line proxy decision debug level sandbox, method, host, decision, intercepted, injected (credential names)
Log line proxy upstream request failed warn level sandbox, host, error
Log line egress refused warn level, kojo proxy (remote mode) only sandbox, host, method, reason. One per refused request.
Log line kojo-proxy restarted info level, kojo serve (remote mode) only replica, previous, instance: the replica’s admin address, the old and the new instance ID
Log line sent a kojo-proxy replica a sandbox's policy again info level, kojo serve (remote mode) only replica, sandbox, instance
Log line could not send a kojo-proxy replica a sandbox's policy again warn level, kojo serve (remote mode) only replica, sandbox, error. Tried again at the next check.
Log line a kojo-proxy replica does not have a sandbox's policy yet: sending it when it answers warn level, kojo serve (remote mode) only sandbox, replicas (how many missed it), error
Log line a kojo-proxy replica still holds a deleted sandbox's policy: deleting it when it answers warn level, kojo serve (remote mode) only sandbox, replicas, error
Log line deleted a sandbox's policy on a kojo-proxy replica that had missed it info level, kojo serve (remote mode) only replica, sandbox
Log lines a kojo-proxy replica does not answer: ... and a kojo-proxy replica answers again warn and info level, kojo serve (remote mode) only replica, and the error
Log lines found a kojo-proxy replica and a kojo-proxy replica is gone: forgetting it info level, kojo serve with admin_discovery: dns replica; pending_deletes for one that is gone
Log line the kojo-proxy admin address answers for more than one replica: ... error level, kojo serve (remote mode) only replica: an address with a load balancer behind it
Log line a kōjō server sent kojo-proxy the sandbox policies info level, kojo proxy instance, settle: the first sync of this instance
Audit entry proxy.deny audit log, embedded mode only Actor sandbox:<id>, target the host, with :port when the port is not 443 or 80 (the allowlist entry that would match). One per refused request.
GET /healthz the proxy port and the admin port kojo-proxy ok
GET /readyz the admin port 200 once the replica is ready for sandbox traffic, 503 before

Header values and tokens are never logged.

In remote mode, kojo proxy registers no metrics, serves no /metrics endpoint and writes no audit entries. It logs every refusal instead, one line at warn level: egress refused, with sandbox, host, method and reason (the decision). Collect those lines with the cluster’s log pipeline. kojo serve, which drives it, counts the policies it sends a replica again in kojo_proxy_policies_resent_total{replica}. The other metrics, including kojo_sandbox_startup_seconds{driver}, are on the Prometheus metrics page.

Running kojo proxy separately

sandbox.proxy.mode decides where kojo-proxy runs:

Mode Where the proxy runs Default for
embedded inside kojo serve, on sandbox.proxy.listen every driver except k8s
remote its own kojo proxy process, which kojo serve drives through the admin API the k8s driver

The sbx driver uses neither: sbx has its own proxy.

Both processes read the same kojo.yaml. For remote it needs:

sandbox:
  driver: k8s
  proxy:
    mode: remote
    listen: ":3128"
    admin_listen: ":3129"
    advertise_url: "${KOJO_PROXY_ADVERTISE_URL}"
    admin_url: "${KOJO_PROXY_ADMIN_URL}"
    admin_discovery: dns
    admin_token: "${KOJO_PROXY_ADMIN_TOKEN}"
    ca_cert_file: /var/run/kojo/proxy-ca/tls.crt
    ca_key_file: /var/run/kojo/proxy-ca/tls.key
Key Default Meaning
listen :3128 Address sandboxes connect to.
admin_listen :3129 Address of the admin API in kojo proxy.
advertise_url none The proxy’s address as sandboxes see it.
admin_url none The admin API as the server reaches it: one replica, or with admin_discovery: dns a name that resolves to every replica.
admin_discovery empty dns to find the replicas through the name of admin_url.
admin_urls none Several replicas at fixed addresses, instead of admin_url.
admin_token none Bearer token of the admin API. Required in remote mode.
sync_timeout 30s How long a new replica waits for a kōjō server to send it the policies before it reports ready anyway.
ca_cert_file, ca_key_file none The proxy’s CA. Set both or neither; several replicas need both, with the same files. When both files are missing they are generated; with neither set, the CA lives in memory and is new on every start.
private_hosts empty Hostnames or *.domain patterns that may resolve to loopback, link-local and private addresses: a forge on a private network.
allow_private false Let sandboxes reach every allowlisted host on loopback, link-local and private addresses. Prefer private_hosts.
upstream_ca_file none Extra root certificates (PEM) the proxy trusts when it connects to a host it injects credentials on.
max_conns_per_sandbox 64 Connections one sandbox may have open through a replica at once; one more gets HTTP 429.
idle_timeout 5m How long a tunnel may carry nothing, and a keep-alive connection go without a request, before the replica closes it.

Start it with the same file:

kojo proxy -f /etc/kojo/kojo.yaml

Run several replicas behind one address for sandboxes, and let kōjō find each one: see Several replicas. Route sandbox traffic only to replicas whose /readyz answers 200. Keep the admin port reachable from the kōjō server only, and the proxy port reachable from sandboxes only. Give the CA files a place that survives a restart and that every replica reads, so running sandboxes trust every replica, before and after a restart.

Two limits of the standalone proxy:

  • Its policies live in memory. After a restart, a replica holds none until kōjō notices and sends them again, a few seconds; with several replicas it takes no sandbox traffic until then. See After a proxy restart.
  • It logs every refusal as egress refused, with the sandbox, the host, the method and the reason. It writes no audit log entries and has no metrics endpoint; the embedded proxy does both through kojo serve.
Scroll to move. + - zoom, 0 fit, Esc close.100%