> ## Documentation Index
> Fetch the complete documentation index at: https://docs.runlayer.com/llms.txt
> Use this file to discover all available pages before exploring further.

# ECS Optional Features

> Prepare and configure agents, ToolGuard, Distribution, observability, and integrations on ECS

Select required features **before the first apply** so their credentials, permissions, quotas, and network access are ready. Each HCL snippet shows module inputs; merge it into `module "runlayer_infrastructure"`. Examples enable features and do not represent the defaults.

## Bedrock and Anthropic

On this ECS deployment path, Runlayer Assistant uses Bedrock in the deployment account by default (model
`global.anthropic.claude-opus-4-8`). Having “some Anthropic model” enabled in the console is not enough — that
specific model (or its base) must be available. To run it on one of your own providers instead (for example an
OpenAI-compatible gateway), an admin picks it under **Runlayer Assistant model** in **Settings → AI Providers**.

Module `v28.1.x+` attaches the model-access IAM actions to the ECS task role
(`GetFoundationModelAvailability`, `PutUseCaseForModelAccess`, Marketplace
subscribe, etc.). You do not add those by hand unless an SCP / boundary strips
them.

```hcl theme={null}
bedrock_auto_model_access = true
bedrock_region            = "" # empty → deployment region

# Self-managed installs: override before first successful auto-submit
# (form is submit-once and permanent). Defaults name "Runlayer".
bedrock_model_access_company_name    = "Example Corp"
bedrock_model_access_company_website = "https://example.com"
bedrock_model_access_industry        = "Technology"
bedrock_model_access_intended_users  = 100

# Custom agents only — not required for Runlayer Assistant
enable_bedrock_anthropic_models = false
# anthropic_api_key = var.anthropic_api_key  # via TF_VAR_*
# platform_llm_trial_default_budget_usd = "50"
```

If Assistant chat returns `does not have access to the Anthropic model yet`,
see [troubleshooting](https://docs.runlayer.com/operations/troubleshooting.md#runlayer-assistant-anthropic-bedrock-model-access).

## Agent runtime

Runlayer Assistant, Security Investigations, and Procedures run on the agent
runtime (Bedrock AgentCore). Without it, Assistant chat fails with
`No agent runtime is provisioned for this deployment`.

```hcl theme={null}
enable_runlayer_agentcore_runtime = true
```

The runtime is independent of custom Agents, a separate entitlement Runlayer
enables for your workspace. `enable_runlayer_agents` only adds infrastructure
custom agents use (the agent event-trigger consumer) and requires the runtime.

AgentCore calls your application URL. The default `PUBLIC` network mode
reaches it over the internet; with WAF IP allowlisting, use
[VPC mode and PrivateLink](https://docs.runlayer.com/deployment/ecs-networking.md#security-configuration).
Before applying, check the runtime's
[egress](https://docs.runlayer.com/deployment/egress-requirements.md#agents-and-runlayer-assistant) and
[AWS permissions](https://docs.runlayer.com/deployment/ecs-prerequisites.md#tools-and-aws-identity); the
apply host also needs the AgentCore prerequisites in the module README.
Sandbox options are under [Agent Sandbox](#agent-sandbox-optional).

## Distribution configuration

The [deployment guide](https://docs.runlayer.com/deployment/terraform.md) configures Distribution with all
three inputs below. Obtain a registered reader key from Runlayer before the
first apply:

```hcl theme={null}
distribution_api_key = var.distribution_api_key
distribution_api_url = "https://distribution.prod.runlayer.com"
openfeature_provider = "flagd"
```

The module stores the key in Secrets Manager and injects the URL as non-secret
runtime configuration. It rejects `flagd` without both reader inputs. The
application default remains WorkOS when the provider input is omitted; setting
the key and URL alone does not switch providers. Existing WorkOS deployments
can stage the reader credentials before explicitly switching to `flagd`.

If Runlayer has registered your account for self-managed Distribution
registration, also pass the IDs Runlayer support provides and the module manages
your registry manifest as a Terraform resource:

```hcl theme={null}
distribution_registry_bucket  = "mcp-catalog"
distribution_registry_source  = "runlayer-customer-deployments"
distribution_target_id        = "managed-aws:<your-account-id>"
distribution_configuration_id = "<uuid-from-runlayer>"
```

Rotate keys with zero gap by setting `distribution_api_key_previous` to the
outgoing key, applying, waiting for ECS services to reach steady state, then
clearing it and applying again. Set `distribution_status = "disabled"` to revoke
access without destroying the stack; move `openfeature_provider` off `flagd` first.

## Optional feature flags

Enable only the features you intend to operate. ToolGuard needs GPU quota and [bootstrap egress](https://docs.runlayer.com/deployment/egress-requirements.md#toolguard-gpu-bootstrap). With WAF IP allowlisting, configure [AgentCore VPC mode and PrivateLink](https://docs.runlayer.com/deployment/ecs-networking.md#security-configuration) before enabling the [agent runtime](#agent-runtime).

### Which optional services need EC2 or a GPU

The application services run on ECS Fargate. Three optional ML services run on EC2 instead, and all three are off by default:

| Input | Instances | What it powers | When it's off |
| - | - | - | - |
| `enable_runlayer_tool_guard` | GPU, `g6f.large` by default (`runlayer_tool_guard_instance_type`) | ToolGuard ML scanners (Tool List Guard, Tool Call Guard, Tool Intent Guard), the common-phrases prompt-injection check, and the [AgentGuard](https://docs.runlayer.com/agentguard.md) behavior scan | Those scanners don't run, and their options don't appear in **Security Scanners**. PII, credential, and invisible-character scanners run in the backend and keep working. |
| `enable_runlayer_topic_cpu` | CPU, `m7i.2xlarge` by default (`runlayer_topic_cpu_instance_type`) | Session topics and titles, tool-removal suggestions for agents, the Tool Surface Reduction scanner, and SkillGuard skill scanning | Those features don't run. Session titles fall back to the first prompt. |
| `enable_runlayer_rev` | GPU, `g6f.large` | Rev, the decision model that judges sessions against smart rules | Smart rules aren't evaluated. |

Rev always runs on `g6f.large`. ToolGuard defaults to `g6f.large`, and `runlayer_tool_guard_instance_type` selects another single-GPU `g6f`, `g6` or `g6e` size. Check GPU quota and availability of the chosen types in your private subnets' AZs before you turn either on.

Runlayer Deploy is always enabled by the ECS module.

```hcl theme={null}
enable_runlayer_agentcore_runtime  = true # Assistant, Security Investigations, Procedures, custom agents
enable_runlayer_agents             = true # custom agents only (event-trigger consumer); requires the runtime
enable_runlayer_tool_guard         = true
enable_runlayer_topic_cpu          = false
enable_runlayer_rev                = false # separate GPU decision-model service
enable_imessage_channel            = false # agent iMessage channel through Sendblue (one line per stack)
enable_runlayer_cimd               = true
enable_runlayer_deploy_healthcheck = false
# runlayer_deploy_use_shared_sg = false
# runlayer_deploy_use_shared_task_role = false

# ToolGuard sizing (when enable_runlayer_tool_guard = true)
# runlayer_tool_guard_desired_count = 2
# runlayer_tool_guard_max_count = 4
# runlayer_tool_guard_timeout = 30   # deprecated for enforcement scans (use the workspace scan latency budget); still sets the tool-list/analyze/models timeout
# runlayer_tool_guard_instance_type = "g6f.large"  # g6f.* fractional L4 | g6.* full L4 | g6e.* L40S
# runlayer_tool_guard_gpu_resource_value = null  # derived: "ALL" on g6f.*, "1" on g6.* / g6e.*
# runlayer_tool_guard_scaling_profile = "conservative" # balanced | aggressive
# runlayer_tool_guard_predictive_scaling_mode = null # disabled | forecast_only | forecast_and_scale (default follows profile)

enable_audit_log_kinesis    = true
audit_log_write_target      = "kinesis"
enable_audit_log_s3_archive = true
# S3 archive alone keeps Aurora hot-window size bounded (default
# audit_log_archive_hot_window_days = 90). In kinesis mode this consumer
# persists audit logs from the stream into Aurora; SIEM export is configured
# separately in the section below.
audit_log_kinesis_consumer_config = {
  enabled       = true
  desired_count = 1
  # Optional CPU autoscaling; see the module README "Audit-log consumer
  # scaling" before setting these.
  # min_capacity = 1
  # max_capacity = 4
}

enable_audit_payload_offload = true
enable_audit_log_spool       = true
enable_toolguard_feedback    = true
enable_tool_output_offload   = false
```

The audit-log consumer deploys start-before-stop, like SIEM export below: ECS
stops an old task only once the replacement's health check reports that it
holds its share of the shards, so each shard is unread for a few seconds per
deploy (records wait in the stream). A backend image without this readiness
signal passes the health check only after a 4-minute fallback, so each deploy
of such an image takes that much longer.

**Saved Bedrock providers for Slack monitors.** The agent-event-trigger consumer
uses its dedicated ECS task role to assume the saved provider role. The module
grants `sts:AssumeRole` only on `arn:aws:iam::*:role/runlayer-bedrock-*` and
`arn:aws:iam::*:role/RunlayerBedrock*`. The saved role must trust the caller's AWS
account/identity with the saved external ID and grant the required model access.
When both `BEDROCK_ENABLED` and `BEDROCK_ANTHROPIC_MODELS_ENABLED` are enabled,
the consumer also receives nonstreaming `bedrock:InvokeModel` access to Claude
foundation models and the deployment account's Claude inference profiles for
the legacy platform fallback.
Upgrade and apply the Terraform module alongside the backend/consumer image;
updating the image alone does not install this permission. After IAM propagation,
verify an authorized monitor canary and its dead-letter alarm.

## ToolGuard capacity and scaling

**ToolGuard scale-out speed.** A new ToolGuard GPU host installs NVIDIA GRID
drivers at boot and takes 10–15 minutes before it serves traffic, so a
scale-out decision is only as fast as the spare hosts already running.
That boot path also needs outbound HTTPS to Ubuntu, NVIDIA GRID S3, Docker,
and related hosts — see [Self-Hosted Egress Requirements → ToolGuard](https://docs.runlayer.com/deployment/egress-requirements.md#toolguard-gpu-bootstrap).
`runlayer_tool_guard_scaling_profile` trades idle GPU cost for
time-to-capacity:

| Profile | Scale-out trigger | Spare EC2 headroom | Instances per step | Scale-out cooldown |
| - | - | - | - | - |
| `conservative` (default) | 50% avg CPU | none (hosts launch after tasks are already pending) | `runlayer_tool_guard_desired_count` | 60s |
| `balanced` | 35% avg CPU | \~20% (capacity provider target 80) | 2 | 30s |
| `aggressive` | 25% avg CPU **or** 60% fleet-average GPU | \~30% (capacity provider target 70) | up to `runlayer_tool_guard_max_count` | 30s (GPU policy: 60s) |

CPU targets are a percent of a `g6f.large` task's CPU reservation; on a larger
`runlayer_tool_guard_instance_type` the same CPU is a smaller percent
(balanced 35% becomes 15% on `g6.xlarge`).

`balanced` and `aggressive` keep one to two extra `g6f.large` instances
running at all times (billed even when idle) so the next task starts
immediately. Scale-in waits 15 minutes on every profile. The dashboard's
**Tasks: Desired vs Running** panel shows how long scale-outs wait on new
hosts. The `runlayer-tool-guard-scale-out-lag` alarm fires only when desired
tasks exceed running tasks for 20 consecutive minutes — longer than a cold
GPU host boot — so a routine scale-out does not trip it; when it does fire,
new hosts are not arriving (check the Auto Scaling group and capacity
provider).

**GPU signal on `aggressive`.** CPU is a weak load signal on a GPU inference
host, so `aggressive` adds a second target-tracking policy on fleet-average
GPU utilization (target 60%). The policy tracks the existing
`RunlayerToolGuard/GPUUtilization` metric (`Environment` dimension,
`Average` statistic): every host whose ToolGuard answers `/health` 200
publishes one sample per minute, so the per-minute average is the mean across
serving GPUs. Hosts that are not serving (capacity-provider spares, hosts
still installing drivers or loading the model, hosts in the recycle drain)
publish nothing and are left out, so the spare pool cannot hold the average
under the target while serving GPUs are busy. No per-host series is added, so
CloudWatch metric cardinality is unchanged.
Scaling takes the higher of the CPU and GPU decisions, so the GPU policy
never forces the fleet below what the CPU or predictive policies request.
Hosts publish GPU metrics from their boot script every 60 seconds, so changes to the ToolGuard launch
template trigger an ASG rolling instance refresh that replaces the
hosts: tasks restart on new hosts as old hosts drain (each restart reloads the
model, so expect a capacity dip per batch). Until the refresh replaces them,
hosts from the previous launch template still publish every 5 minutes and so
land in only one of every five 1-minute averages.

**GPU alarms.** On every profile, with `enable_runlayer_tool_guard_alarms`
(default on), two alarms watch the same GPU utilization series, which CPU-based
scaling and the `high-cpu` alarm do not see. With today's models a ToolGuard
host runs out of CPU well before its GPU, so GPU is rarely the limit.

* `runlayer-tool-guard-high-gpu` fires when fleet-average GPU utilization stays
  above 70% for 15 minutes (three 5-minute averages): the whole fleet is
  GPU-bound, usually after a model or batch change. It does not see one busy
  host among idle ones (one of two hosts at 100% averages about 50%).
* `runlayer-tool-guard-gpu-pegged` fires when the busiest host reads above 90% in
  10 of 15 minutes: a GPU held by a stuck kernel or process, or a model or batch
  change that made serving GPU-bound. The metric has no host dimension, so run
  `nvidia-smi` on each host. Replace a single pegged host; on a fleet at its
  minimum, raise the minimum by one first and let the new host serve, since a
  host takes up to 15 minutes to boot. If several hosts are high, roll back a
  recent model or batch change, or treat it like `high-gpu`.

**Predict latency alarm.** `runlayer-tool-guard-predict-p95` fires when the p95
of every successful predict request, fleet-wide and server-side, is above a
threshold in 12 of the last 15 minutes (minutes with fewer than 10 requests
don't count): the fleet is past its latency knee. Short bursts of concurrent
requests slow only the minute they land in, so they don't fire it. The threshold
defaults by `runlayer_tool_guard_instance_type`: 400 ms on g6f.large (and on
types not yet measured), 150 ms on g6.xlarge; during an instance type cutover,
the higher of the two. Set `runlayer_tool_guard_predict_p95_alarm_threshold_ms`
if your busy-hour p95 sits near the default. When it fires, check whether the
service is at its task ceiling (raise `runlayer_tool_guard_max_count`) or a
scale-out is stuck (`scale-out-lag`); after a model or batch change at normal
load, roll that change back.

`high-gpu`, `gpu-pegged` and `predict-p95` are non-paging alerts. On ALARM they
notify the ToolGuard alerts topic and, with `enable_monitoring`, the topics in
`critical_alerts_extra_sns_topic_arns`. On OK they notify only those extra
topics, like the ToolGuard alarms that page.

**GPU query timeout alarm.** A host whose GPU or driver is wedged stops
publishing GPU utilization, so `high-gpu`, `gpu-pegged` and GPU scaling cannot
see it. Its `nvidia-smi` read gives up after 10 seconds and publishes
`RunlayerToolGuard/GPUQueryTimeouts` instead, and
`runlayer-tool-guard-gpu-query-timeout` fires when that happens in 3 of 5
minutes, counted across the fleet. It pages like `gpu-errors`. The same metric
with an `InstanceId` dimension names the host; terminate it. The alarm
deliberately pages instead of replacing the host automatically: a driver fault
on every host would otherwise replace the whole fleet into the same fault.

**Predictive scaling.** Because a reactive scale-out cannot beat the 10–15
minute host boot, the module also creates an ECS predictive scaling policy
on the ToolGuard service. It forecasts the next 48 hours of demand hourly
from up to 14 days of ToolGuard `predict` request history and raises the
task count `runlayer_tool_guard_predictive_scheduling_buffer_seconds`
(default 1200) before each forecast hour, so GPU hosts are booting before
the load arrives. `conservative` runs it in `forecast_only` mode (forecasts
are recorded but never acted on); `balanced` and `aggressive` run
`forecast_and_scale`. Override the profile default with
`runlayer_tool_guard_predictive_scaling_mode` (`disabled`, `forecast_only`,
`forecast_and_scale`). The first forecast appears after 24 hours of metrics;
review it in the ECS console (service → **Service auto scaling**) or with
`aws application-autoscaling get-predictive-scaling-forecast`, then flip
`forecast_only` → `forecast_and_scale` once the curve matches your traffic.
Predictive scaling only scales out; the CPU policy still handles scale-in and
unforecast bursts. Every policy stops below `runlayer_tool_guard_max_count`,
which reserves ceil(25%) of it, at least one host (8 allows 6 tasks, 4 allows
3, 2 allows 1), because each task needs a whole GPU host and a
rolling deploy starts each replacement task before it stops the old one.
`runlayer_tool_guard_max_count` stays the GPU host limit. In regions where ECS predictive scaling is unavailable
(for example `il-central-1`) the policy is skipped automatically; the
`runlayer_tool_guard_predictive_scaling_mode_effective` output reports the
mode actually applied.

**Why the load is floored.** The forecast learns daily and weekly patterns
from the load metric, so a few days with scanning switched off would teach
it that those weekdays are idle and under-provision them for the next two
weeks. Before forecasting, weekday hours (Mon–Fri UTC) below
`runlayer_tool_guard_predictive_load_floor_fraction` (default `0.5`) of the
window's mean hourly request count are raised to that floor, so off days
look like quiet business days instead of zero; weekends forecast from actual
traffic (`runlayer_tool_guard_predictive_load_floor_weekdays_only = false`
floors every day, `0` disables the floor). Capacity is sized so each task
receives `runlayer_tool_guard_predictive_target_requests_per_task_per_minute`.
Left null (default), it is the per-task rate measured for
`runlayer_tool_guard_instance_type`: `50` per minute on `g6f.large` (3000 per
hour), `250` on `g6.xlarge`, and `50` on other, unmeasured types (which
over-provisions a faster host). On `g6f.large`, `50` keeps ToolGuard `predict`
p95 near its floor; latency rises steeply once a task serves more than roughly
twice that rate. `250` on `g6.xlarge` keeps the same headroom: a benchmark
showed a `g6.xlarge` task serving at least five times what a `g6f.large` task
does. While `runlayer_tool_guard_cutover` is set, the lower of the two types'
rates applies. Raise the target to trade latency for fewer hosts, lower it for
more headroom.

Running tasks are read from Container Insights (`RunningTaskCount`) when it
is enabled, otherwise from the GPU Auto Scaling group's in-service instance
count (one task per host). The Auto Scaling group count also includes the
spare hosts `balanced` and `aggressive` keep warm (roughly 20% and 30% of
the fleet), so without Container Insights requests per task read low by that
share and the forecast under-provisions. Pair `forecast_and_scale` with
`container_insights = "enabled"`; `terraform plan` warns when it is not.

## Agent Sandbox (Optional)

Procedures also need the agent sandbox: their code is validated and test-run
inside it. Without the agent runtime (`enable_runlayer_agentcore_runtime = true`),
creating or validating a Procedure returns 503. Select a [network configuration](https://docs.runlayer.com/deployment/ecs-networking.md#security-configuration) that allows AgentCore to reach the application before applying.

```hcl theme={null}
# Separate Sentry DSN for sandbox errors (does not reuse backend sentry_dsn)
# Pass via TF_VAR / secrets backend — never commit
runlayer_agent_sandbox_sentry_dsn = var.agent_sandbox_sentry_dsn

# Optional image overrides
# runlayer_agent_sandbox_image_uri = "123456789012.dkr.ecr.us-east-1.amazonaws.com/runlayer/agent-sandbox:1.28.162"
# With WAF IP allowlisting, use VPC + PrivateLink (not PUBLIC):
# enable_privatelink              = true
# runlayer_agentcore_network_mode = "VPC"
# runlayer_agentcore_consumer_vpc_id = "vpc-xxxxx"
# runlayer_agentcore_consumer_private_subnet_ids = ["subnet-xxxxx", "subnet-yyyyy"]
# runlayer_agentcore_max_lifetime_seconds = 3600
# runlayer_agentcore_idle_timeout_seconds = 900

# Per-agent network access policies (requires VPC mode). Roll out in order:
# 1. VPC mode with direct egress left on (the defaults above).
# 2. sandbox_egress_mode = "proxy"                  # every run routes through the proxy; direct egress stays as a bypass
#    Routing starts without a proxy-health gate; initial proxy startup can interrupt runs.
#    Verify healthy proxy targets and wait for the backend rollout to finish before step 3.
# 3. sandbox_egress_mode = "proxy_only"             # proxy becomes the only path and policies are enforced
# sandbox_egress_proxy_egress_ports = [443, 8443]    # 443 is always open; add ports that host:port policies may use
# sandbox_egress_proxy_image_uri    = "…/runlayer/sandbox-egress-proxy:1.28.500"
```

With the egress proxy enabled, every sandbox request to the public internet is
authenticated per run and checked against the agent's
[network access policy](https://docs.runlayer.com/platform-agents.md#network-access-policy). Runlayer
traffic stays on PrivateLink and is never proxied.

> [!WARNING]
>
> Network access policies are enforced only by this ECS / AgentCore sandbox
> runtime. The in-cluster Kubernetes agent sandbox (`sandboxMode: k8s`) does not
> enforce them yet: an agent's policy is stored but has no effect there.

By default, Agent Sandbox routes LLM calls through the backend Anthropic proxy. To use OpenAI or an OpenAI-compatible gateway for **custom** agents, add a provider in **Settings → AI Providers** (no Terraform change needed).

This Terraform path provisions the **ECS / AgentCore** sandbox. In-cluster [kubernetes-sigs Agent Sandbox](https://agent-sandbox.sigs.k8s.io/) (`sandboxMode: k8s`, gVisor or Kata on the nodes) is operator/GKE — see [Runlayer Operator — K8s Agent Sandbox](https://docs.runlayer.com/deployment/runlayer-operator.md#k8s-agent-sandbox-sandboxmode-k8s).

Runlayer Assistant runs on Bedrock in this account by default, so it works without configuring a provider. Admins can move it to one of the workspace's providers under **Runlayer Assistant model** in **Settings → AI Providers**. Model access is handled as described above; this module exposes it as `bedrock_auto_model_access`, `bedrock_model_access_company_name`, `bedrock_model_access_company_website`, `bedrock_model_access_industry` and `bedrock_model_access_intended_users`.

Backend egress for WorkOS AuthKit, Bedrock, and AgentCore is listed in [Self-Hosted Egress Requirements](https://docs.runlayer.com/deployment/egress-requirements.md).

## LLM gateway

```hcl theme={null}
enable_llm_gateway            = true
llm_gateway_listener_priority = 12
# llm_gateway_image_uri = "123456789012.dkr.ecr.us-east-1.amazonaws.com/runlayer/llm-gateway:1.28.162"
# Pass via TF_VAR_llm_gateway_runlayer_api_key — never commit
# llm_gateway_runlayer_api_key = var.llm_gateway_runlayer_api_key
```

## Microsoft Teams

Optional. Off unless all five values are set — the module variable is the client
secret, the rest ride `additional_backend_env_vars`.

Provisioning creates a per-agent Entra app registration and Azure Bot Service
resource in **your** Entra tenant and Azure subscription, so a self-managed
install needs its own multi-tenant app registration (Graph application
permissions `Application.ReadWrite.All`, `AppCatalog.ReadWrite.All`,
`TeamsAppInstallation.ReadWriteForUser.All`, admin-consented), an Azure
resource group whose IAM grants that app **Azure Bot Service Contributor**, and
the `Microsoft.BotService` provider registered on the subscription.

```hcl theme={null}
# ms_teams_app_client_secret = var.ms_teams_app_client_secret  # via TF_VAR_*

additional_backend_env_vars = {
  MS_TEAMS_APP_CLIENT_ID         = "00000000-0000-0000-0000-000000000000"
  MS_TEAMS_RUNLAYER_TENANT_ID    = "00000000-0000-0000-0000-000000000000"
  MS_TEAMS_AZURE_SUBSCRIPTION_ID = "00000000-0000-0000-0000-000000000000"
  MS_TEAMS_AZURE_RESOURCE_GROUP  = "runlayer-ms-teams-bots"
}
```

`MS_TEAMS_APP_URL` defaults to `APP_URL` (`https://<domain_name>`). Register
`https://<domain_name>/api/v1/integrations/ms-teams/admin-consent-callback` as a
Redirect URI (Authentication → Web) on that app registration, or admin consent
fails with `AADSTS500113`.

Each tenant that installs an agent's bot must also enable **Upload custom apps**
in its Teams Admin Center setup policy; without it, publishing to the tenant's
app catalog returns 403 no matter how many times it is retried.

`domain_name` is effectively immutable once agents are provisioned: each agent's
Azure Bot resource stores the messaging endpoint captured at creation time and
is never rewritten, so changing the domain orphans existing bots until each is
deleted and recreated.

## iMessage channel

Optional, off by default. Lets people text an agent from Messages; the user
side is in [iMessage](https://docs.runlayer.com/platform-imessage.md). The stack doesn't run any Apple
hardware: [Sendblue](https://sendblue.com) rents a phone number ("line") that
sends and receives iMessage (with SMS fallback) through its API.

The stack has one line, Runlayer's, configured in Terraform. One agent answers
it at a time, so one workspace on the stack uses iMessage at a time: the first
workspace whose admin turns it on holds the number until it turns it off. On a
stack several workspaces share, agree on which one before you enable the
channel.

```hcl theme={null}
enable_imessage_channel = true

sendblue_from_number    = "+15551234567"
sendblue_api_key_id     = var.sendblue_api_key_id     # via TF_VAR_*
sendblue_api_secret_key = var.sendblue_api_secret_key # via TF_VAR_*
sendblue_webhook_secret = var.sendblue_webhook_secret # via TF_VAR_*, long random value
```

`enable_imessage_channel` sets `IMESSAGE_CHANNEL_ENABLED`, which shows the
**Text message** card on agent profiles in Go. The apply stores the key
pair and webhook secret in one Secrets Manager secret and hands them, with
`SENDBLUE_FROM_NUMBER`, to the backend service and the shared worker only. The
plan fails unless all four `sendblue_*` values are set with the flag.

### Before you apply

* **A Sendblue account with a dedicated line.** Sign up at
  [sendblue.com](https://sendblue.com) (or `npx @sendblue/cli setup`). The free
  plan shares one number across customers and only reaches contacts you
  verify first; for an agent anyone in the organization can text, use a
  dedicated line (Sendblue's AI Agent plan is inbound-first: people text the
  line, the agent replies). Copy the line's number and the API key pair
  (dashboard, or `sendblue show-keys`).
* **Who can reach it.** Anyone can text the line. Runlayer ignores texts from
  people who haven't linked their number to a Runlayer account, apart from one
  link reply every 10 minutes.
* **Data path.** Texts and the agent's replies pass through Sendblue
  (SOC 2 Type II). Review that with your security team the same way as any
  other messaging integration.

### Point Sendblue at the stack

In the line's Sendblue account (**Developer → Webhooks**), add a **receive**
webhook with the `imessage_channel_sendblue_webhook_url` output,
`https://<domain_name>/api/v1/integrations/imessage/sendblue/receive`, and
`sendblue_webhook_secret` as its secret. Sendblue sends the secret in the
`sb-signing-secret` header; the backend rejects any call without the right one.

Sendblue webhooks are per account. If the account has other lines, texts to
them reach the webhook too and are ignored: only texts to
`sendblue_from_number` start runs.

With WAF IP allowlisting on, the webhook must still reach
`https://<domain_name>`: allow Sendblue's webhook egress IPs (ask Sendblue
support) in `waf_allowlist_ipv4_cidrs`, or texts get 403s and nothing happens.
The backend also needs outbound HTTPS to `api.sendblue.co`.

### Give the line a name and photo

Optional. Without a contact profile, Messages shows the line as a bare number.
Set one once with Sendblue's
[contact sharing API](https://docs.sendblue.com/api-v2/contact-sharing) and
the line's key pair. The photo must be a public JPEG or PNG URL:

```bash theme={null}
curl -X POST https://api.sendblue.co/api/v2/contact-sharing/profile \
  -H "sb-api-key-id: $SENDBLUE_API_KEY_ID" \
  -H "sb-api-secret-key: $SENDBLUE_API_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -d '{"fromNumber": "+15551234567", "firstName": "Acme", "lastName": "Agent", "photoUrl": "https://example.com/agent.png"}'
```

The backend asks Sendblue to share it with a linked phone number whenever that
number's text starts a run, and Sendblue shares it with each chat at most once
a day. Until the profile is set, Sendblue refuses each share with a 409,
logged as `imessage_sendblue_name_share_failed`; texts and replies are
unaffected.

### Operating it

* **Status.** The agent page shows the number and **Runlayer's line**, or
  **No line**. It does not call Sendblue, so a wrong key shows up as failed
  replies, not on that badge.
* **Replies.** Each reply is queued in the database, then sent right away.
  One person's replies go out one at a time and in order. If Sendblue is
  down, rate-limits, or rejects the keys, the worker's `imessage_outbox_sweep`
  (every minute) retries it, up to 5 attempts over about 9 minutes, and the
  replies after it wait. A message Sendblue declines (for example, the person
  opted out) is not retried, and the rest of that answer is dropped. A reply
  still unsent after a day (the line's config was missing) is dropped too.
  Logs: `imessage_sendblue_send_failed`.
* **Read receipts and typing.** A text the agent takes is marked read, and
  the agent shows typing while its run works. Both are best effort: failures
  are logged (`imessage_sendblue_read_receipt_failed`,
  `imessage_sendblue_typing_failed`) and change nothing else.
* **What "sent" means.** A reply counts as sent once Sendblue accepts it. If
  Sendblue's response is lost, the reply still counts as sent (Sendblue may
  have queued it) and is never resent, because Sendblue takes no idempotency
  key. Delivery to the phone is Sendblue's from there. Failures after that
  (for example, an unreachable phone) show in Sendblue's dashboard, matched
  by the message handle stored on the reply when one came back. If a run's
  answer never reached the queue (the server failed right after the run
  finished), the sweep queues it within a couple of minutes.
* **Rotating keys.** Rotate in Sendblue, update the variables and apply; a new
  secret version rolls the backend and the worker onto it. Texts Sendblue
  sends with an old webhook secret get 401s, and Sendblue retries each one up
  to 3 times, so update both sides together.
* **Offboarding an organization**: turn iMessage off on the agent that
  answers, with the API call in
  [Turn it on for your workspace](https://docs.runlayer.com/platform-imessage.md#turn-it-on). To retire
  the channel, set `enable_imessage_channel = false`, apply, and delete the
  webhook in Sendblue.

Kubernetes deployments set the same backend settings directly:
`IMESSAGE_CHANNEL_ENABLED`, `SENDBLUE_FROM_NUMBER` and the secrets
`SENDBLUE_API_KEY_ID`, `SENDBLUE_API_SECRET_KEY` and `SENDBLUE_WEBHOOK_SECRET`
on both the backend and the worker.

## Audit SIEM, sessions, and hook events

Audit logs and session events use separate S3 exports. Enable either or both
for ingestion into your SIEM:

* **Audit logs** include tool activity, policy decisions, security events, and
  administrative changes. Set `enable_audit_log_siem_export = true`. With
  `audit_log_write_target = "aurora"`, the worker exports through an outbox;
  audit-log Kinesis is optional. S3 audit archiving is a separate retention
  feature and does not enable SIEM export. See [Audit-log export](https://docs.runlayer.com/platform-audit-logs.md#siem-export-s3).
* **Session events** include captured prompts, reasoning, tool calls, and
  scanner verdicts. Set `enable_hook_events_pipeline = true` and uncomment
  `session_siem_export_kinesis_consumer_config` below to enable the dedicated
  export consumer. Enabling the hook-events pipeline alone does not enable
  session export. See [Session export](https://docs.runlayer.com/platform-sessions.md#siem-export).

For self-hosted ECS, configure these settings in your Terraform module. To
write to existing buckets, uncomment the corresponding `*_external_s3_bucket`
settings and replace the example names. Both exports can use the same bucket
with separate `*_s3_prefix` values. Without an external destination, Terraform
creates a bucket for each enabled export in your deployment's AWS account.
Direct writes use your deployment's ECS task role. To write through another
IAM role, set `*_assume_role_arn` together with the required `*_external_id`
and `*_external_s3_bucket` for that export.
Configure destination bucket and KMS policies, plus your SIEM's S3 reader
permissions, notifications, and schemas, separately.

Optionally set `hook_events_alert_email` to receive pipeline-health emails
through Amazon SNS. Alerts fire when the hook-events consumer Lambda's error
rate exceeds 20% for two consecutive five-minute periods, or its processing lag
exceeds five minutes in three consecutive five-minute periods. Recovery notifications are also sent. Confirm the SNS
subscription email to receive notifications; leaving the setting unset disables
these email alerts. These alarms monitor the hook-events consumer Lambda, which
is provisioned only when ML data export (`data_export_bucket_arn`), the Sparkle
worker, or `enable_hook_events_parquet_archive` is set — with only session SIEM
export on, no Lambda and none of these email alarms are created. The session
SIEM exporter is a separate ECS consumer.

Session export starts with new events and does not backfill earlier sessions.
It contains unredacted content; session privacy settings do not apply to the
export, so restrict access to the destination bucket.

```hcl theme={null}
enable_hook_events_pipeline = true
# hook_events_alert_email = "ops@example.com"

enable_audit_log_siem_export = true
# Aurora/outbox defaults; these can be omitted for that mode.
# audit_log_write_target   = "aurora"
# enable_audit_log_kinesis = false

# Write to your bucket (or omit external_* to use the Runlayer-managed bucket)
# audit_log_siem_export_external_s3_bucket = "acme-audit-siem"
# audit_log_siem_export_external_s3_region = "us-east-1" # defaults to deployment region
# audit_log_siem_export_assume_role_arn    = "arn:aws:iam::123456789012:role/siem-writer"
# audit_log_siem_export_external_id        = "REPLACE_ME"
# audit_log_siem_export_s3_prefix          = "runlayer/audit" # optional; default: "audit-logs"
# audit_log_siem_export_read_role_arns     = ["arn:aws:iam::123456789012:role/siem-reader"]

# session_siem_export_kinesis_consumer_config = { enabled = true, desired_count = 1 }
# session_siem_export_external_s3_bucket = "acme-session-siem"
# session_siem_export_external_s3_region = "us-east-1" # defaults to deployment region
# session_siem_export_s3_prefix          = "runlayer/sessions" # optional; default: "sessions"
# sessions_read_from_postgres = false
# session_materializer_config           = { min_capacity = 1, max_capacity = 4 } # ingest
# session_materializer_compactor_config = { min_capacity = 1, max_capacity = 4 }

# data_export_bucket_arn = "arn:aws:s3:::acme-hook-events-export"
```

If your deployment already uses `audit_log_write_target = "kinesis"`, keep its
existing audit-ingestion configuration. To export directly from that stream,
also enable the independent SIEM export consumer below, alongside
`enable_audit_log_siem_export = true`. This exports normal streamed events
without routing them through the database outbox. Set both audit prefix
variables to the same value so stream exports and outbox fallback exports use
the same destination prefix:

```hcl theme={null}
audit_log_siem_export_kinesis_consumer_config = {
  enabled       = true
  desired_count = 1
  # Optional CPU autoscaling; see the module README "Audit SIEM export
  # consumer scaling" before setting these.
  # min_capacity = 1
  # max_capacity = 4
}
audit_log_siem_export_s3_prefix         = "runlayer/audit"
audit_log_siem_export_kinesis_s3_prefix = "runlayer/audit"
```

The consumer deploys start-before-stop: a replacement task starts first, and
ECS stops the old task only once the replacement's health check reports that it
holds its share of the shards. The remaining tasks claim the shards an old task
releases within a few seconds, so an upgrade pauses exports for a few seconds
per shard. A backend image without this readiness signal passes the health
check only after a 4-minute fallback, so each deploy of such an image takes that
much longer. Delivery is at-least-once, so a deploy can export a few records a
second time; deduplicate on `audit_log_id` downstream.

## Binary packages and downloads

```hcl theme={null}
enable_binary_package_distribution = true
# runlayer_download_token = var.runlayer_download_token  # via TF_VAR_*
# runlayer_downloads_base_url = "https://downloads.example.com"
```

## AI Watch snapshot signing

Only for AI Watch Local Proxy. Generate the deployment key and get a delegation from Runlayer as described in [AI Watch snapshot delegation](https://docs.runlayer.com/deployment/runlayer-provided-inputs.md#ai-watch-snapshot-delegation), then pass both:

```hcl theme={null}
ai_watch_snapshot_signing_key = var.ai_watch_snapshot_signing_key          # via TF_VAR_*; the deployment key's seed
ai_watch_snapshot_delegations = file("ai-watch-snapshot-delegations.json") # from Runlayer; not secret
```

Tasks read both only at start. After an apply that changes either, force a new `backend-service` deployment (see [Secrets management](https://docs.runlayer.com/deployment/ecs-configuration.md#secrets-management)).

* **Renew** before the delegation's `not_after` (at most 90 days): replace the file with the one Runlayer sends, apply, and restart.
* **Rotate the key** by changing both inputs in the same apply: a delegation names one key, so a new key needs new delegations.

## Customer OpenTelemetry

Export metrics from the backend, and/or run an OTEL collector sidecar that ships to **your** collector:

```hcl theme={null}
otel_exporter_otlp_metrics_endpoint = "https://otel.example.com:4317"
otel_exporter_otlp_metrics_protocol = "grpc"
otel_service_name                   = "runlayer-backend"

otel_collector_config = {
  enabled         = true
  export_endpoint = "otel-collector.example.com:4317" # your collector; not localhost
  export_insecure = false
}

flow_metrics_collection_enabled      = true
flow_trace_adaptive_sampling_enabled = true
```

## Secrets, Sentry, and catalog

```hcl theme={null}
# Prefer TF_VAR_* / a secrets backend — do not commit values
# secret_key  = var.secret_key   # must pair with master_salt, or omit both
# master_salt = var.master_salt
# sentry_dsn  = var.sentry_dsn
mcp_catalog_api_key = var.mcp_catalog_api_key # required for catalog / onboarding
# distribution_api_key = var.distribution_api_key

mcp_catalog_api_url = "" # empty → backend default

frontend_sentry_dsn                = ""
frontend_sentry_traces_sample_rate = "0.1"
sentry_relay_enabled               = true
# sentry_relay_upstream = "https://sentry.example.com/"
# sentry_relay_config   = { ... }

oauth_broker_url = "" # empty → module default when broker is used
# oauth_client_registration_rate_limit_per_hour = 1000
```

## Deployment identity

```hcl theme={null}
customer_id     = "acme"
deployment_name = "staging"
infra_version   = "v33.1.0"
```

For Sentry Relay credentials, follow [Sentry Relay Credentials from WorkOS Vault](https://docs.runlayer.com/deployment/sentry-relay-vault.md). For software upgrades and rollback, follow [Updates](https://docs.runlayer.com/operations/updates.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.