# Networking Configuration

Source: https://agenta.ai/docs/self-host/infrastructure/networking

This guide explains Agenta's network topology, how containers communicate with each other, and the environment variables that control networking behavior and connectivity.

## Network Topology

Agenta uses a Docker-based network architecture with a dedicated bridge network for container communication and Traefik as the reverse proxy for external access.

```
                        ┌─────────────────────────────────────┐
                        │            External Users           │
                        └─────────────────┬───────────────────┘
                                          │ HTTPS/HTTP
                        ┌─────────────────▼───────────────────┐
                        │        Host Server (80/443)         │
                        └─────────────────┬───────────────────┘
                                          │
┌─────────────────────────────────────────▼───────────────────────────────────┐
│                           agenta-network (bridge)                           │
│                                                                             │
│  ┌───────────────────────────────────────────────────────────────────────┐  │
│  │                      Traefik (Reverse Proxy)                          │  │
│  │              HTTP: 80 -> HTTPS: 443 -> Dashboard: 8080               │  │
│  │                   SSL termination and routing                         │  │
│  └─┬─────────────────────┬─────────────────────┬─────────────────────────┘  │
│    │                     │                     │                            │
│    │ /                   │ /api/               │ /services/                  │
│    ▼                     ▼                     ▼                            │
│  ┌─────────────┐  ┌─────────────┐   ┌────────────────────┐                 │
│  │     Web     │  │     API     │   │   Services API     │                 │
│  │   :3000     │  │   :8000     │   │      :8080         │                 │
│  └─────────────┘  └──────┬──────┘   └─────────┬──────────┘                 │
│                          │                     │                            │
│                          │ Redis queues         ▼                           │
│                          │ / streams   ┌─────────────────┐                  │
│                          │             │  runner :8765   │                  │
│                          │             │ (internal only) │                  │
│                          │             └────────┬────────┘                  │
│                          │                      │                           │
│                          ▼                      │                           │
│  ┌──────────────────────────────────────────────────────────────────────┐   │
│  │                            Worker Pool                               │   │
│  │   worker-streams (records, events, spans),                           │   │
│  │   worker-queues (webhooks, triggers, interactions, evaluations),     │   │
│  │   cron                                                               │   │
│  └─────────────────────────┬────────────────────────────────────────────┘   │
│                            │                    │ (from runner)              │
│                            ▼                    ▼                           │
│  ┌──────────────────────────────────────────────────────────────────────┐   │
│  │                     Infrastructure Layer                             │   │
│  │                                                                      │   │
│  │ ┌──────────────┐ ┌──────────────────┐ ┌────────────┐ ┌────────────┐  │   │
│  │ │  PostgreSQL  │ │      Redis       │ │SuperTokens │ │ seaweedfs  │  │   │
│  │ │    :5432     │ │  :6379 / :6381   │ │   :3567    │ │   :8333    │  │   │
│  │ │Core+Tracing  │ │queues + caching  │ │auth+sess   │ │bundled or  │  │   │
│  │ │      DB      │ │                  │ │            │ │external S3 │  │   │
│  │ └──────────────┘ └──────────────────┘ └────────────┘ └────────────┘  │   │
│  └──────────────────────────────────────────────────────────────────────┘   │
│                                                                             │
└─────────────────────────────────────────────────────────────────────────────┘

```

## Container Communication Patterns

### External Access Flow

```
Internet → Traefik (80/443) → Internal Services
├── / → web-mobile:3000 (Frontend)
├── /api/ → api:8000 (Backend API)
└── /services/ → services:8080 (includes completion/chat endpoints)
```

### Internal Service Communication

```
Web Container:
├── → api:8000 (Backend API calls)
└── → services:8080 (Playground and model interaction endpoints)

API Container:
├── → postgres:5432 (Database operations)
├── → redis-volatile:6379, redis-durable:6381 (queues, streams, caching)
├── → supertokens:3567 (Authentication)
├── → runner:8765 (Stop and kill via AGENTA_RUNNER_INTERNAL_URL)
└── → worker pool (Task delegation via queues/streams)

Services API Container:
├── → postgres:5432 (agent and service state)
├── → LLM providers (model calls)
└── → runner:8765 (agent run dispatch via AGENTA_RUNNER_INTERNAL_URL)

Runner:
├── → seaweedfs:8333 or external S3 endpoint (durable storage mount)
└── → api:8000 (session record writes)

Worker Pool:
├── → redis-volatile:6379, redis-durable:6381 (task and event consumption)
├── → postgres:5432 (Data access)
├── → api:8000 (coordination and shared backend logic)
└── → external webhook destinations (worker-queues, webhooks loop)
```

## Network Environment Variables

### External Access Configuration

These variables control how external users access Agenta:

| Variable | Purpose | Example | Description |
|----------|---------|---------|-------------|
| `TRAEFIK_DOMAIN` | Domain routing | `localhost`, `agenta.mydomain.com` | Primary domain for routing |
| `TRAEFIK_PORT` | HTTP port | `80` | External HTTP port |
| `TRAEFIK_HTTPS_PORT` | HTTPS port | `443` | External HTTPS port |
| `AGENTA_API_URL` | API endpoint | `http://localhost/api` | External API URL |
| `AGENTA_WEB_URL` | Frontend URL | `http://localhost` | External frontend URL |
| `AGENTA_SERVICES_URL` | Services URL | `http://localhost/services` | External services URL template |
| `AGENTA_API_INTERNAL_URL` | Internal API URL between services and backend | `http://api:8000/api` | Internal API URL |
| `DOCKER_NETWORK_MODE` | Docker network mode hint for runtime URL logic | `bridge` | Should be `bridge` for compose-based deployments |

### Internal Service Communication

These variables configure how containers communicate internally. Use `REDIS_URI` for a single Redis instance, or split with the volatile/durable URLs for separate caches and queues.

| Variable | Purpose | Example | Description |
|----------|---------|---------|-------------|
| `POSTGRES_URI_CORE` | Core database | `postgresql+asyncpg://user:pass@postgres:5432/agenta_core` | Core database connection |
| `POSTGRES_URI_TRACING` | Tracing database | `postgresql+asyncpg://user:pass@postgres:5432/agenta_tracing` | Tracing database connection |
| `POSTGRES_URI_SUPERTOKENS` | Auth database | `postgresql://user:pass@postgres:5432/agenta_supertokens` | SuperTokens database connection |
| `REDIS_URI` | Single Redis (fallback) | `redis://redis:6379/0` | Used when split URLs are not set |
| `REDIS_URI_VOLATILE` | Redis for caches/channels | `redis://redis-volatile:6379/0` | Falls back to `REDIS_URI` |
| `REDIS_URI_DURABLE` | Redis for queues/streams | `redis://redis-durable:6381/0` | Falls back to `REDIS_URI` |
| `SUPERTOKENS_CONNECTION_URI` | Auth service | `http://supertokens:3567` | SuperTokens service URL |
| `AGENTA_RUNNER_INTERNAL_URL` | Runner URL | `http://runner:8765` | Points the Services API (runs) and the platform API (Stop, kill) at the agent runner; default in compose, generated from `agentRunner.*` in Helm |

:::note Daytona sandboxes and the store tunnel
Compose deployments using Daytona remote sandboxes require the `with-tunnel` compose profile, which starts an ngrok tunnel (it needs an `NGROK_AUTHTOKEN`). The remote sandbox mounts durable storage over the public internet, so the store endpoint must be reachable. Railway and Kubernetes deployments expose the store endpoint publicly and do not need ngrok.
:::

### Port Mapping (Optional)

These variables control external port exposure for direct access:

| Variable | Default | Purpose | Description |
|----------|---------|---------|-------------|
| `POSTGRES_PORT` | `5432` | Database access | External PostgreSQL port (development) |
| `NGINX_PORT` | `80` | Alternative proxy | Nginx port (when using Nginx) |

## Traffic Routing Rules

### Traefik Routing Configuration

#### Frontend Routing

```yaml
# Route: / → web-mobile:3000
Rule: Host(`${TRAEFIK_DOMAIN}`) && PathPrefix(`/`)
Target: web-mobile:3000
Processing: Direct forwarding
SSL: Automatic (production)
```

#### API Routing

```yaml
# Route: /api/ → api:8000
Rule: Host(`${TRAEFIK_DOMAIN}`) && PathPrefix(`/api/`)
Target: api:8000
Processing: Strip `/api` prefix
Middleware: Path prefix stripping
```

#### Services Routing

```yaml
# Route: /services/ -> services:8080
Rule: Host(`${TRAEFIK_DOMAIN}`) && PathPrefix(`/services/`)
Target: services:8080
Processing: Strip `/services` prefix

# Examples served by the same services container:
# /services/completion/* -> services:8080/completion/*
# /services/chat/* -> services:8080/chat/*
```

## SSL/TLS Configuration

### Development (HTTP)

```bash
TRAEFIK_PORT=80
AGENTA_API_URL=http://localhost/api
AGENTA_WEB_URL=http://localhost
```

### Production (HTTPS)

```bash
TRAEFIK_PORT=80
TRAEFIK_HTTPS_PORT=443
AGENTA_SSL_DIR=/path/to/certificates
AGENTA_API_URL=https://agenta.mydomain.com/api
AGENTA_WEB_URL=https://agenta.mydomain.com
```

### SSL Certificate Management
- **Automatic**: Let's Encrypt via Traefik (HTTP challenge)
- **Storage**: `${AGENTA_SSL_DIR}/acme.json`
- **Renewal**: Automatic every 60-90 days
- **Redirect**: HTTP → HTTPS automatic

::: info Network Security
The services are isolated within Docker bridge network. None of the services are exposed to the host network (except Traefik)
:::

## Network requirements for agent runs

With the LLM gateway on (the default), an agent's model calls go from the sandbox to the Agenta API, and from the API to the model provider. A run works when three conditions are true:

1. The sandbox reaches the Agenta API.
2. The API reaches the model provider.
3. Nothing between them cuts a long model call.

The sandbox is where the agent runs: `local` (in the runner container) or `daytona` (a cloud sandbox).

### 1. The sandbox reaches the Agenta API

A sandbox on the runner calls the API at its internal address. A Daytona sandbox calls the public address in `AGENTA_API_URL`.

**Docker Compose.** The runner calls `AGENTA_API_INTERNAL_URL`, which defaults to `http://api:8000`. Test it from the runner container:

```bash
docker compose -f hosting/docker-compose/oss/docker-compose.gh.yml \
  --env-file hosting/docker-compose/oss/.env.oss.gh \
  exec runner curl -sS -o /dev/null -w '%{http_code}\n' http://api:8000/health
```

The answer is `200`.

**Helm.** The runner calls `agenta.apiInternalUrl`. When it is unset, the chart sets `http://<fullname>-api:8000` (`http://agenta-api:8000` for release `agenta`). Test it from the runner pod (release `agenta`, namespace `agenta`):

```bash
kubectl -n agenta exec deploy/agenta-runner -- \
  curl -sS -o /dev/null -w '%{http_code}\n' http://agenta-api:8000/health
```

The answer is `200`.

**Daytona.** The sandbox runs in the cloud, so `AGENTA_API_URL` must be an address the internet reaches, such as `https://agenta.example.com/api`. A run on `localhost`, `127.0.0.1`, `::1` or `host.docker.internal` stops before the sandbox starts. Test it from a machine outside your network:

```bash
curl -sS -o /dev/null -w '%{http_code}\n' https://agenta.example.com/api/health
```

The answer is `200`. When the runner starts a Daytona sandbox, it checks from inside the sandbox that the address answers within 10 seconds.

Plain HTTP works only to a loopback address or to the deployment's own `AGENTA_API_URL`. Plain HTTP to any other host fails with `gateway_insecure_endpoint`.

### 2. The API reaches the model provider

The API container calls the provider, for example `api.openai.com` or `api.anthropic.com`. The sandbox never calls the provider. Give the API container outbound DNS and HTTPS access to every provider your projects use.

**Docker Compose.** Test it from the API container:

```bash
docker compose -f hosting/docker-compose/oss/docker-compose.gh.yml \
  --env-file hosting/docker-compose/oss/.env.oss.gh \
  exec api curl -sS -o /dev/null -w '%{http_code}\n' https://api.openai.com/v1/models
```

**Helm.** Test it from the API pod:

```bash
kubectl -n agenta exec deploy/agenta-api -- \
  curl -sS -o /dev/null -w '%{http_code}\n' https://api.openai.com/v1/models
```

**Daytona.** No change: test the API container as for Compose or Helm.

An HTTP status such as `401` means the provider is reachable. `000`, or an error such as `Could not resolve host`, means it is not.

A custom provider on a private address or on plain HTTP, such as Ollama at `http://10.0.0.7:11434/v1`, also needs the egress guard open. The Docker Compose templates set `AGENTA_GATEWAYS_INSECURE_EGRESS_ALLOWED=true`. The Helm chart leaves the guard on: set `gatewayEgress.insecureAllowed: true` in your values file. With the guard open, any user who can create a custom provider can make the API call an address inside your network. See [Agenta gateways](https://agenta.ai/docs/self-host/configuration.md#agenta-gateways).

### 3. Nothing cuts a long model call

A model can think for minutes before it sends the next part of its answer. The API waits up to 600 seconds between two parts. A proxy between the sandbox and the API must not close the connection sooner. Set its read timeout on the paths that start with `/api/gateways/` to 1820 seconds, the value Agenta uses for its other long routes.

**Docker Compose.** The bundled Traefik sets no response timeout. The bundled nginx (`--profile with-nginx`) sets 1820 seconds on the gateway paths. If you keep your own copy of `nginx.conf`, check it:

```bash
awk 'index($0, "location ~ ^/api/gateways/") {f=1} f && /proxy_read_timeout/ {print; exit}' \
  hosting/docker-compose/oss/nginx/nginx.conf
```

The answer is `proxy_read_timeout 1820s;`.

**Helm.** A Daytona run passes the ingress. A run on the local sandbox does not. See [Long model calls through an ingress](https://agenta.ai/docs/self-host/guides/deploy-to-kubernetes.md#long-model-calls-through-an-ingress). Check the annotations of the Ingress:

```bash
kubectl -n agenta get ingress agenta -o jsonpath='{.metadata.annotations}'
```

**Daytona.** Daytona runs pass every proxy in front of your public address: your ingress, load balancer or reverse proxy. Set the read timeout on each of them.

## Troubleshooting Network Issues

### Connection Testing

```bash
# Test database connectivity
docker exec :container-name: nc -zv postgres 5432

# Test Redis connectivity
docker exec :container-name: redis-cli -h redis-volatile -p 6379 ping
docker exec :container-name: redis-cli -h redis-durable -p 6381 ping
```

### Port Conflicts

```bash
# Check port usage
sudo netstat -tulpn | grep :80
sudo lsof -i :443

# View container port mappings
docker ps --format "table {{.Names}}\t{{.Ports}}"
```

### Traefik Routing Issues

```bash
# Access Traefik dashboard
http://localhost:8080

# Check Traefik logs
docker logs :container-name:

# Verify service registration
curl -s http://localhost:8080/api/http/services
```

### DNS Resolution

```bash
# Test external domain resolution
nslookup agenta.mydomain.com
dig agenta.mydomain.com +short

# Test from multiple DNS servers
nslookup agenta.mydomain.com 8.8.8.8
nslookup agenta.mydomain.com 1.1.1.1
```

### Agent run errors

Each row starts with the text a failed agent run shows, or with the symptom when no text shows.

| Error text | Cause | Fix |
|---|---|---|
| `The sandbox cannot reach the Agenta API at <origin>. Set AGENTA_API_URL to an address that the sandbox can reach.` | A Daytona sandbox got no answer from the API address within 10 seconds, or the address is `localhost`, `127.0.0.1`, `::1` or `host.docker.internal`. | Set `AGENTA_API_URL` to a public address, such as `https://agenta.example.com/api`. See [condition 1](#1-the-sandbox-reaches-the-agenta-api). |
| `The Agenta API cannot reach <host>. Give the API container outbound access to the model provider.` | The API container cannot resolve or connect to the provider host. | Allow outbound DNS and HTTPS from the API container to that host. See [condition 2](#2-the-api-reaches-the-model-provider). |
| `blocked target: Upstream URL resolves to a blocked IP range.` | A custom provider is on a private address, and the egress guard is on. This is the Helm default. | Helm: set `gatewayEgress.insecureAllowed: true`. Compose: set `AGENTA_GATEWAYS_INSECURE_EGRESS_ALLOWED=true`. Recreate the API. |
| `blocked target: Upstream URL must use https.` | A custom provider is on plain HTTP, and the egress guard is on. | The same as the row above. |
| `Gateway credentials require an effective HTTPS endpoint.` (code `gateway_insecure_endpoint`) | The gateway address is plain HTTP to a host that is not loopback and not the deployment's own `AGENTA_API_URL`. | Serve the deployment over HTTPS. Set the same `AGENTA_API_URL` on the services and runner containers. |
| `gateway credentials require an effective HTTPS endpoint; serve the deployment over HTTPS` | The runner refused the gateway address for the reason in the row above. An older runner image also refuses a plain HTTP LAN address. | The same as the row above. Deploy the runner image of the same release as the services image. |
| `The model <model> is not in the model list of the provider <slug>. Open the provider in Settings and add the model.` | The agent names a model that the custom provider does not list. | Open the provider in **Settings** and add the model. |
| `Open the provider <slug> in Settings and save it once.` | The custom provider has no gateway record. | Open the provider in **Settings** and save it. |
| `The <provider> connection this agent would use has no name the gateway can route by. Name a connection in the agent.` | The gateway cannot address the connection that the agent would use. | Pick a named connection in the agent's model settings. |
| `multiple connections for provider '<provider>' (<names>); name one in the config` | The project has more than one connection for the provider, and the agent names none. | Pick one of the listed connections in the agent's model settings. |
| `Secret for this Bedrock connection is invalid: it holds an AWS access key, and the gateway calls Bedrock only with a Bedrock API key. Add a Bedrock API key to the connection.` | The Bedrock connection has an AWS access key and no Bedrock API key. | Add a Bedrock API key to the connection in **Settings**. |
| `Secret for this Bedrock connection is invalid: it has no Bedrock API key. Add one to the connection.` | The Bedrock connection has no Bedrock API key. | The same as the row above. |
| `deployment 'bedrock' is not supported by harness 'pi_core' in v1; use a direct or OpenAI-compatible custom connection` | A Pi agent uses a Bedrock connection while the LLM gateway is off. | Turn the LLM gateway on (`AGENTA_LLM_GATEWAY_ENABLED=true`). |
| `The model must be a bare Gemini model id.` | The Gemini model id has a path or a prefix. | Use the model id only, such as `gemini-3.8-flash`. |
| `Agenta's included models aren't enabled for your organization. Use your own provider key, or contact us.` | The agent uses a built-in model while the LLM gateway is off. | Turn the LLM gateway on, or pick a model on your own provider key. |
| A streamed answer stops after 30 or 60 seconds. | A proxy between the sandbox and the API has a short read timeout. | Set the read timeout on `/api/gateways/` to 1820 seconds. See [condition 3](#3-nothing-cuts-a-long-model-call). |
