AI Agent Gateway vs Agent Sandbox: Divide the Boundaries

Yilia Lin

Yilia Lin

July 7, 2026

Technology

An AI agent gateway governs calls that cross a network boundary: model requests, tool or MCP calls, and agent-to-agent traffic. An agent sandbox constrains the process that runs the agent: its filesystem, operating-system privileges, compute, and network reachability. They solve different problems, and a production agent that can execute code usually needs both.

The important design rule is simple: a control exists only on the paths that cannot bypass it. A gateway cannot stop a local shell command that never reaches the gateway. A container cannot protect a SaaS API if the agent can leave the container with an unrestricted network path and a long-lived credential.

This guide gives platform and security teams a boundary map, a reference request path, and a negative-test checklist for deciding where each control belongs.

If your immediate task is onboarding an agent to model traffic rather than isolating its execution, use the separate AI gateway onboarding guide. This article focuses on the security boundary between the two layers.

The Short Answer

QuestionGatewaySandbox
Which model, MCP server, API, or upstream agent may this identity call?Primary controlNot sufficient by itself
Where are upstream credentials stored and injected?Gateway or credential brokerSandbox should receive only a scoped caller credential
Which files, processes, syscalls, devices, and local sockets can code access?Does not control themPrimary control
How much CPU, memory, disk, and runtime may one task consume?Can limit network requests, not local resourcesPrimary control
Can the process call an unapproved internet host directly?Only if traffic is forced through itNetwork policy or sandbox egress control must prevent bypass
Can a tool call be authorized and audited centrally?Yes, when that tool path crosses the gatewayCan record local execution, but does not automatically govern remote APIs

Do not choose between these controls by comparing feature lists. Start with the action that can cause harm, then put an enforcement point immediately before that action.

Draw the Boundary Before Choosing Products

An agent system has at least four actors:

  1. the agent process or harness;
  2. the execution environment where commands and files are handled;
  3. the gateway or broker that mediates remote calls;
  4. the model, tool, API, or upstream agent that performs work.

An agent runs inside a sandbox that controls local execution. Approved remote calls follow a forced path through an agent gateway to models, tools, APIs, and upstream agents, while sandbox or network egress policy blocks a direct internet bypass.

The sandbox contains execution. The gateway mediates approved remote destinations. Network policy joins the two by making the gateway the only allowed path for governed traffic.

This layered design follows the same principle in current NCSC agentic-AI guidance: separate the agent scaffolding, command-execution environment, and inference infrastructure, and control what each layer can reach. The OWASP Secure Coding with AI Cheat Sheet likewise recommends sandboxed execution, resource limits, restricted egress, and short-lived credentials for coding agents.

What the Gateway Actually Controls

A gateway controls a request only after the request reaches it. On that path, it can authenticate the caller, authorize a named resource, apply request or concurrency limits, keep upstream credentials away from the agent, and produce a centralized decision record.

For example, the AISIX 1.9.0 Agent Gateway documentation describes an A2A path where a caller uses an AISIX caller API key, the gateway checks allowed_agents, and the gateway applies its configured upstream authentication. For A2A message calls, AISIX resolves input guardrails attached at the environment, caller API key, and team scopes and runs them before upstream dispatch. Model- and MCP-server-scoped guardrail attachments do not apply to this path, and A2A guardrails do not inspect the upstream agent's response. Model, MCP, and A2A paths therefore do not automatically have identical attachment or inspection behavior. See the version-current AISIX Agent Gateway overview before assigning a control to a path.

That distinction leads to three gateway rules:

  • Authenticate the workload, not a human-readable label. A client-supplied session ID, tool name, or user field is not identity unless a trusted authentication mapping establishes it.
  • Authorize the exact resource and action. “May call the gateway” is broader than “may call this model, this MCP tool, or this upstream agent.”
  • Keep bypass paths visible. Direct provider endpoints, raw internet egress, local CLIs, browser sessions, and sidecar credentials can all bypass a gateway.

The gateway is therefore a traffic-policy boundary, not a complete execution boundary.

What the Sandbox Actually Controls

A sandbox determines what the agent process can do locally even if the model or prompt is hostile. Depending on the isolation technology, that can include:

  • filesystem mounts and writable paths;
  • process, user, syscall, and capability boundaries;
  • CPU, memory, disk, process-count, and execution-time limits;
  • device and metadata-service access;
  • network namespaces and egress policy;
  • lifecycle cleanup and state persistence.

Kubernetes SIG Apps Agent Sandbox v1.0.10 makes this separation concrete. Its Sandbox resource manages a singleton, pod-backed workload; optional SandboxClaim, SandboxTemplate, and SandboxWarmPool resources manage allocation and reuse. The project's quickstart for that version also states that a basic KIND setup does not provide stronger container isolation by itself; gVisor or Kata Containers are separate choices. Creating a resource named “sandbox” is not proof of a particular isolation strength.

The sandbox still needs an outbound policy. A process isolated from the host may remain able to reach the public internet, cloud metadata, internal services, or a model provider directly. If the security design says “all model and tool traffic goes through the gateway,” enforce that statement with network policy, routing, firewall rules, or a service-mesh egress boundary. Do not rely on the agent to remember the rule.

Put Credentials on the Correct Side

Long-lived provider or SaaS credentials inside the sandbox collapse the boundary. A compromised process can read the credential and use it through any reachable path.

A safer sequence is:

  1. The orchestrator creates one task or session identity.
  2. The sandbox receives a short-lived caller credential scoped to that task.
  3. Network policy allows the sandbox to reach the gateway and only the other destinations the task requires.
  4. The gateway maps the caller to approved models, tools, APIs, or upstream agents.
  5. Provider and tool credentials remain gateway-side or in a dedicated credential broker.
  6. Task expiry revokes the caller credential and triggers sandbox cleanup.

This does not make the gateway a secret vault by definition. Verify how the selected product stores, rotates, and injects credentials, and whether a managed control plane, self-hosted gateway, or external secret system owns each step.

Build an Acceptance Matrix

Test the architecture from the perspective of a compromised agent, not only the happy path.

TestExpected enforcement pointPassing evidence
Call an allowed model through the gatewayGatewayRequest succeeds; the authenticated workload and served resource are recorded
Call a model outside the caller allowlistGatewayRequest is denied before upstream dispatch
Call an allowed remote tool with the wrong action or argumentsTool/API authorization layerSide effect is denied; a policy decision identifies the rule
Call the provider directly from the sandboxSandbox network policyConnection is blocked even if the agent knows the hostname
Read a host SSH key or cloud CLI profileSandbox filesystem boundaryFile is absent or inaccessible
Reach the cloud metadata serviceSandbox egress boundaryConnection is blocked
Fork processes or fill disk beyond the task budgetSandbox resource policyLimit is enforced and the task is terminated or throttled as designed
Reuse an expired task credentialGateway identity layerRequest is denied; expiry is distinguishable from an upstream error
Send traffic through an unmonitored alternate proxyNetwork architectureRoute is blocked or produces equivalent policy and audit evidence
Delete the task while a command is runningOrchestrator and sandbox lifecycleProcess, writable state, and temporary credential are cleaned up according to policy

Record the exact status, log, policy decision, and postcondition for each negative case. A log that says “denied” is not enough when the side effect still occurred. Conversely, a blocked side effect with no useful attribution leaves incident responders guessing.

Decide Which Layer Owns Each Failure

Use this decision method when a requirement is ambiguous:

  1. Name the protected resource. Is it a local file, Kubernetes API, model, MCP tool, SaaS API, or upstream agent?
  2. Name the last trusted component before the action. Put the primary check there.
  3. Find every alternate path. Include direct DNS, local sockets, browser sessions, sidecars, cached credentials, and host mounts.
  4. Add a containment layer. Assume the primary check can be misconfigured or bypassed.
  5. Specify observable evidence. Decide which identity, policy, destination, and result must be recorded.
  6. Exercise the negative path. Verify denial and cleanup before granting production access.

If the action is a local shell command, the sandbox is the last enforceable boundary. If the action is a remote model or tool request, the gateway or target service can authorize it—but only when the network makes that path unavoidable.

Common Architecture Mistakes

“The gateway secures the agent”

It secures the traffic that traverses it. It does not constrain local code execution, files, browser state, host credentials, or direct egress.

“The sandbox blocks all remote misuse”

Only if its egress policy is defined and enforced. A sandbox with unrestricted internet access and a provider credential still permits direct calls.

“A tool allowlist is enough”

Tool names do not express every authorization decision. The target service may still need resource-level and argument-level checks, especially for write operations.

“One audit log proves the whole action”

Gateway logs prove what the gateway observed. Sandbox logs prove local execution. The target system proves whether a side effect occurred. Correlate them with a task identifier, but do not treat a caller-supplied correlation value as trusted identity.

A Minimum Production Design

For an agent that reads code, runs commands, and calls remote models or tools, start with this minimum:

  • one sandbox per task or clearly defined tenant boundary;
  • non-root execution, a read-only base filesystem, bounded writable storage, and explicit CPU, memory, process, and time limits;
  • no automatic host credentials or Kubernetes service-account token;
  • default-deny egress with explicit access to the gateway and required infrastructure;
  • short-lived workload identity at the gateway;
  • gateway-side provider and tool credentials;
  • per-resource authorization, request limits, and decision logs;
  • cleanup tests for normal completion, timeout, cancellation, and orchestrator failure;
  • correlation across sandbox, gateway, and target-system evidence.

The result is defense in depth with explicit ownership. The sandbox answers “what can this process touch?” The gateway answers “which remote resources may this authenticated workload call?” Network policy ensures the second answer cannot be skipped.

Start by drawing your real request and execution paths, including every bypass. Then use the matrix above to turn the diagram into tests. For the gateway side, review AISIX model, MCP, and Agent Gateway documentation against the exact deployment and version you operate; do not assume one protocol path inherits another path's controls.

Tags:
Share article link