Sandbox for AI agents: control what leaves it

Formal isn't a sandbox. Formal Endpoint runs inside the one you already use, from Cursor Cloud Agents and Devin to E2B, Modal, Daytona, Kubernetes and Amazon ECS, checks what the agent sends, adds API keys from outside the sandbox and names who started each run.

logs · cloud agent sandboxexample
VERIFY  devin oidc  session for leo@acme.com, machine user cloud-agents
ALLOW   GET api.stripe.com/v1/balance  key added on the Connector
BLOCK   POST api.stripe.com/v1/refunds  read-only policy
BLOCK   merge of acme/app #42  Cloud agents cannot merge pull requests
# env | grep -i stripe in the sandbox: no output

The problem

What does a sandbox for AI agents leave open?

A sandbox for AI agents, whether an E2B sandbox, a Modal container or a Cursor Cloud Agent VM, keeps the agent’s code away from your hosts. It leaves three things to you: the domains it allows, the secrets in its environment and the identity of whoever launched it. Formal isn’t an AI agent sandbox: Formal Endpoint runs inside the one you already use and handles those three things for cloud agents.

  1. Every allowed domain accepts any request

    “every allowed domain is still an exfiltration channel.”
    Kevin Qiu, Lead Security Engineer, Latent Health
  2. Every key in the environment can be read

    Teams store API keys as environment secrets on the agent platform, so every session can read the raw key, print it or send it to any host the sandbox allows. Prompt-injected code doesn't have to escape anything: reading an environment variable is ordinary behavior for code.

  3. A run with no person attached

    Anyone on the team can start a Cursor Cloud Agent or a Devin session from Slack or Linear. Its requests carry the token the agent was given, so the API's audit log can't say which engineer asked for the work.

today · no policy on the pathexample
01
cloud agent · run 4821POST api.github.com/repos/acme/app/issuesALLOWED
02
sandbox · injected codeenv | grep -i stripeALLOWED
03
cursor-agentPOST api.github.com/graphql, no requesterALLOWED

# Allowing github.com lets the agent clone, push, turn on auto-merge or paste what it read into a public issue. The egress setting sees a hostname; the merge request travels inside TLS.

Definition

What is a sandbox for AI agents?

sandbox for AI agentsnoun

A sandbox for AI agents is an isolated environment, usually a container, a gVisor sandbox or a microVM, where an agent writes and runs code, installs packages and executes tests without touching the host or other tenants. Each task or session gets its own, thrown away or snapshotted afterwards. The isolation covers the kernel, the file system and processes; network access is a setting, usually a list of allowed domains.
  • Containers

    Share the host kernel.

  • gVisor

    gVisor puts a user-space kernel between the agent’s system calls and the host.

  • Firecracker microVMs

    Firecracker boots a minimal KVM virtual machine per sandbox with five emulated devices.

  • Agent Sandbox on Kubernetes

    The SIG project Agent Sandbox gives sandboxes their own API and lets you pick gVisor or Kata Containers underneath. “AI sandbox” sometimes names this category too, though it more often means an environment for testing models.

  • Picking one

    It comes down to how long a session lives, how fast it has to start and how much you trust the code it runs. E2B, Modal or Daytona save you operating the isolation layer; Agent Sandbox or your own Pods keep it in your cluster. We don’t rank them: the controls below work in each.

How it works

How Formal works inside an AI agent sandbox

Four steps, each with a docs guide: OIDC integrations, the Endpoint in cloud agents, keeping API keys out of sandboxes and Logs.

  1. Step 1 of 4

    Give the agent an identity

    Create an OIDC integration from the platform's preset, pin it with a claim condition such as your Cursor team ID or Devin organization ID, and map it to a machine user.

    OIDC INTEGRATIONSexample
    • Cursor · claims.team_idCLOUD-AGENTS
    • Devin · claims.org_idCLOUD-AGENTS
    • owner_email or requesting_user_emailPERSON
  2. Step 2 of 4

    Install the Endpoint where the agent runs

    Bake the headless package into the Cursor or Devin environment, an E2B template, a Modal Sidecar image or a Daytona snapshot, or add the Kubernetes or ECS sidecar.

    WHERE IT RUNSexample
    • Cursor and Devin environments✓
    • E2B template, Modal Sidecar, Daytona snapshot✓
    • Kubernetes or ECS sidecar✓
  3. Step 3 of 4

    Select traffic and hold the keys

    Network rules pick the hostnames to intercept for that machine user. For an API that needs a key, the rule forwards to a Connector and a Native User adds it there.

    NETWORK RULESexample
    • api.stripe.com forwarded to the ConnectorTOKEN INJECTED
    • api.github.com interceptedALLOWED
    • no rule matched: passes through, not loggedALLOWED
  4. Step 4 of 4

    Enforce and review

    Start each policy in Dry-run and switch it to Active once its matches look right. Logs show every intercepted request with the machine user and, for Cursor and Devin, the person behind the run.

    POLICY ROLLOUTexample
    • Dry-run: mergePullRequest acme/app #42 would matchDRY RUN
    • Active: mergePullRequest acme/app #42BLOCKED
    • GET pulls/42 by cloud-agents for mayaALLOWED

Capabilities

AI agent sandbox security with Formal

Formal closes those gaps from inside the sandbox, with the Endpoint next to the agent, a Connector in your network for anything that needs a credential, and the rules, policies and logs in the Control Plane.

Inspect

Every request checked inside the sandbox

Formal Endpoint is a headless Linux package that runs beside the agent. In Cursor Cloud Agents, Devin and E2B it uses Transparent Mode, so tools need no proxy settings. Network rules select the hostnames it intercepts for the cloud agent’s machine user; any connection no rule matches passes through untouched and isn’t logged. For the hosts it does intercept, the Endpoint terminates TLS with its own local CA and evaluates each request against your Rego policies.

  • The Cursor and Devin guides set enforce = true and fail = "closed": a matched request fails when the Endpoint can’t reach the Connector, instead of leaving without a decision
  • On Modal and Daytona, the Endpoint runs in a separate container, a Modal Sidecar or a linked Daytona sandbox, as an explicit proxy; the agent’s container has no other route out, so a client that ignores HTTPS_PROXY gets no connection at all
  • Code in the agent’s container can’t read the Sidecar or change its configuration. Sidecars are a Modal beta, and Daytona’s sandbox-level network settings need a Tier 3 or 4 organization
endpoint · devin sessionexample
run +1mdevin for leoGET api.github.com/repos/acme/app/pullsALLOWED
run +6mdevin for leoConnector unreachable, fail = closedBLOCKED
Attribute

Each run tied to a person

Cursor and Devin mint an OIDC token for every run. The Formal OIDC integration verifies it, checks a claim condition such as claims.team_id for Cursor or claims.org_id for Devin, and maps the run to a machine user. The End-User Email Expression then names the person: Cursor’s token carries them as claims.owner_email, Devin’s as claims.requesting_user_email, and Formal looks up the user with that email.

  • Formal verifies the agent’s token cryptographically, while the email is what the platform asserts about its user
  • Create a Formal user for every engineer who launches cloud agents before the integration goes live; for Connector access through federation tokens, resolution fails closed: no person, no token
  • Cursor runs Cloud Agents in isolated environments with restricted outbound connections and routes their access to data through Formal: each Cloud Agent connects with a dedicated Formal identity with limited access, and Formal adds the employee who started the task
  • Agent identity covers machine users and OIDC integrations for every kind of workload, and our engineers wrote up why we chose OIDC over stored secrets for our own cloud agents
logs · cloud agentsexample
sam@acme.com> machine user cloud-agents, last hour
machine userend userclaimrequest
cloud-agentsmaya@acme.comowner_emailGET /v1/balance
cloud-agentsleo@acme.comrequesting_user_emailPOST /graphql
cloud-agentsmaya@acme.comowner_emailgit push acme/app
3 rowsALLOWED
Block

Stopping cloud agents from merging their own pull requests

Most teams start with one policy: an agent may open a pull request, and a person merges it. A Control Plane recipe, Prevent Merges by Cloud Agents, sets up a GitHub network rule scoped to your cloud agent machine users, along with a policy that blocks enablePullRequestAutoMerge, enqueuePullRequest and mergePullRequest in GraphQL, plus the REST merge call.

  • Enabling auto-merge from inside the agent returns HTTP 403 with the policy, session and request IDs
  • Agents still open and update pull requests
  • Cursor and Devin each have an integration page with the platform-specific setup
endpoint · cursor-cloud-agentexample
run +4mcursor-agent for mayaPOST api.github.com/graphql createPullRequestALLOWED
run +9mcursor-agent for mayaenablePullRequestAutoMerge acme/app #42BLOCKED
run +9mcursor-agent for mayaPUT /repos/acme/app/pulls/42/mergeBLOCKED
Approve

Database access for one session

The Devin database access guide starts from a block: Devin can’t query the database until someone says yes. Devin asks, the engineer who started the session gets a Slack message, and their approval lifts the block for one requester and one Devin session, then expires after the duration in the request.

  • The workflow that creates the policy suspension runs as its own machine user, so Devin never holds the power to approve itself
  • Just-in-time access covers the workflow side
slack · #devin-accessexample
FormalAPP
devin for leo requests database access for this session
Requester
leo@acme.com
Session
this Devin session
Duration
from the request
leo approved for one requester and one Devin session, until the duration runs out.
APPROVED

Keys

Keys stay outside the sandbox

Take the key out of the platform’s secrets and set it on the Connector. A network rule matches the API hostname for the cloud agent’s machine user and forwards the request to the Connector, where a Native User adds the credential and a policy decides whether the request may go. Code in the sandbox still calls api.stripe.com, with no base URL or client change. The rule is from Keep API keys out of cloud agent sandboxes.

  • Linux ignores pre_tcp, which is why pre_tls checks the user again
  • Leave out forward_to_connector and the Endpoint evaluates the request locally with no key added, and Stripe answers 401
  • The guide’s test: env | grep -i stripe in the sandbox prints nothing, the balance call succeeds, and with the read-only policy active a POST to /v1/refunds gets the Formal block message
  • Native Users also cover Basic credentials, header and query API keys, and keys a hook fetches from a vault, so any HTTP API works this way
  • Where the platform mints OIDC tokens (Cursor, Devin, Modal, and Amazon ECS through the task role), the Endpoint exchanges that token for a short-lived machine session; on Modal, only the Sidecar gets the token
  • The E2B and Daytona guides use a dedicated machine user’s API key that the orchestrator passes to the Endpoint at start-up, never baked into a template or snapshot; in E2B the Endpoint runs as root and the agent as the default user. The Kubernetes sidecar reads its key from a Secret. Rotate those keys on a schedule; a machine user’s API key stays valid for 10 years or until refreshed
Keep API keys out of cloud agent sandboxes ›
network rule · stripetext
{
  "condition": {
    "pre_tcp": user.id == "<CLOUD_AGENT_MACHINE_USER_ID>",
    "pre_tls": hostname == "api.stripe.com" &&
      user.id == "<CLOUD_AGENT_MACHINE_USER_ID>",
    "post_tls": true
  },
  "outputs": {
    "resource_name": "stripe",
    "forward_to_connector": true
  }
}

Supported platforms

Cloud agents and AI agent sandboxes we support

The controls are the same everywhere; what changes is where the Endpoint sits and how it proves who it is. Each platform has a docs guide. In the agent VM (Cursor, Devin, E2B), the headless Debian package runs in Transparent Mode, so curl, git and SDKs need no proxy settings.

  • Cursor Cloud Agents

    Agent VM, started by a named terminal on every run. Signs in with the Cursor OIDC token; the person is claims.owner_email. Cursor security.

    OIDC · person named
  • Devin

    Agent VM, as a formal.service systemd user unit kept in the snapshot. Signs in with the Devin OIDC token; the person is claims.requesting_user_email. Devin security.

    OIDC · person named
  • E2B

    Custom template, Endpoint as root, agent as user. Signs in with a machine user API key; machine user only. E2B guide.

    API key
  • Modal

    Sidecar (Modal beta), explicit proxy. Signs in with the Modal OIDC token, given to the Sidecar only; machine user, and policies read Modal claims such as sandbox_id. Modal guide.

    OIDC
  • Daytona

    Linked Endpoint sandbox, explicit proxy. Signs in with a machine user API key; machine user only. Daytona guide.

    API key
  • Kubernetes

    Native sidecar, Kubernetes 1.29 or later. Signs in with a machine user API key in a Kubernetes Secret; machine user only. Kubernetes guide.

    API key
  • Amazon ECS

    Sidecar container added by a Terraform module. Signs in with the task role over OIDC; machine user only. ECS guide.

    OIDC
  • Claude Managed Agents

    Not tested: we haven’t run Formal inside Anthropic-hosted sandboxes. What stays on you.

    Not tested

E2B has a second identity path. Its Workload Identity gives each sandbox execution a short-lived JWT-SVID, which Formal’s E2B preset accepts; E2B’s egress proxy adds the token to requests, so sandbox code never handles it, and Connector policies can read the project, sandbox and template IDs. The E2B section of the OIDC docs covers it. That path mints Connector credentials and is separate from the Endpoint setup above.

Outside the sandbox

Why the controls sit outside the sandbox

Every sandbox platform has its own egress setting: allow_out in E2B, outbound_domain_allowlist in Modal, a network allow list in Daytona. The guides still use them, to let the sandbox reach only Formal and the Connector. The rules that look at requests live in the Control Plane instead, written once in CEL and Rego and applied the same way to Cursor, Devin, E2B, Modal, Daytona, Pods and ECS tasks, with one log. That also keeps them out of the agent’s reach: this Control Plane Permission, from the cloud agents guide, denies the cloud agent’s machine user every Formal API and Control Plane operation, while the Endpoint’s own sign-in and log APIs keep working.

  • An agent with a shell and the machine user’s session gets HTTP 403 when it tries to change a network rule or a policy
  • Approvals follow the same split: the workflow that lifts a block runs as its own machine user, so the agent can’t approve its own access
  • The Kubernetes sidecar runs as root with NET_ADMIN, so its namespace needs the Privileged Pod Security Standard
  • On Fargate the Endpoint can only act as a local HTTP proxy, and a client that ignores proxy settings connects directly; use EC2 or Managed Instances when all egress must go through Formal
  • The E2B, Daytona and Kubernetes setups depend on an API key you have to rotate, and Anthropic-hosted sandboxes are untested
Restrict Control Plane access ›
control plane permission · cloud agentrego
package formal.app

import future.keywords.if

default allow = true

allow = false if {
  input.user.id == "<CLOUD_AGENT_MACHINE_USER_ID>"
}

Architecture

Where your agents run

Vendor cloud agents, sandbox platforms and your own clusters. In the agent VM, Cursor Cloud Agents, Devin and E2B run the headless package next to the agent. In a container beside it, Modal runs the Endpoint in a Sidecar and Daytona in a linked sandbox. As a sidecar you deploy, a native sidecar in Kubernetes Pods (1.29 or later) and a sidecar container in Amazon ECS tasks, added by a Terraform module. Anthropic-hosted Claude Managed Agents sandboxes aren’t on the list: we haven’t tested Formal inside them.

Formal Endpoint architecture: an egress proxy on laptops, VMs and agent sandboxes that applies network rules and Rego policies before AI agent traffic reaches LLM providers, MCP servers and SaaS APIs.
Formal Endpoint sits in the agent's path and applies policy before a request leaves the machine.

Deployment

The Endpoint runs where the agent runs. The Connector stays in your network.

One Control Plane for agents on laptops, in vendor VMs and in your clusters. AI coding agent security covers the same agents on engineers’ laptops, agent identity covers the machine users and OIDC integrations behind each run, and the MCP gateway covers the MCP servers a cloud agent calls. They share one set of policies and logs across AI agent security.

Formal Endpoint in cloud agents

The headless Debian package runs in Cursor Cloud Agent and Devin environments and signs in with the platform’s short-lived OIDC token (guide).

Formal Endpoint in pods and tasks

A native sidecar in Kubernetes Pods, injected by label with the Helm chart, and a sidecar container in Amazon ECS tasks (Kubernetes, ECS).

Formal Connector in your VPC

Linux on AMD64 or ARM64: AWS ECS Fargate behind a Network Load Balancer, or Helm on EKS, GKE, AKS or on-premises Kubernetes. In production, run 2 or more nodes behind a load balancer (deployment).

Your identity provider

People sign in with SSO, and SCIM keeps users and groups in sync. Policies use the groups you already manage.

Logs in your SIEM

Log integrations forward Formal logs to AWS S3, Google Cloud Storage, Azure Blob Storage, Datadog, Splunk or Panther.

Policy and configuration as code

Policies are written in Rego. Manage Formal with Terraform, Pulumi or the Kubernetes Operator.

Audited controls

Formal holds SOC 2 Type II and ISO/IEC 27001. The reports are on security.formal.ai.

Our own cloud agents reach production this way, and the lesson our engineers drew from it is that “agent access should be modeled as a temporary delegation”. Each run gets its sandbox from the platform and its delegation from Formal, with a person’s name on it.

Cloud agents in production at Cursor

Technologies secured
10+
Resources secured
1,000+
Logs per week
40M+
Sessions per week
600K+
“We've limited the amount of data that those cloud agents can access and we're able to tie that back to the specific user who is using that cloud agent, which is a feature that I'm only aware of Formal having.”
Roy Xu
Roy Xu
Software Engineer, Security, Cursor
Read the Cursor story ›

FAQ

Questions about sandboxes for AI agents

Buying and fit

Which sandbox is best for AI agents?

The one whose isolation and lifecycle match the work: a microVM if the agent runs code nobody reviewed, a gVisor or plain container if start time and density matter more, a hosted AI agent sandbox if you’d rather not run the isolation layer. Formal doesn’t change that choice, because its controls run inside each of them. What a sandbox for AI agents is covers the isolation types.

Can agents we build ourselves use the same controls?

Yes, if they run in Kubernetes Pods, Amazon ECS tasks, E2B, Modal or Daytona. Modal also injects MODAL_IDENTITY_TOKEN into every Function container, so a Function can mint a Formal federation token and reach a Connector without a stored secret. The same policies and logs then cover your own agents and vendor cloud agents.

AI agents

Do cloud agents need API keys inside the sandbox?

No. The key lives on a Connector, and a Native User adds it to the requests the Endpoint forwards, so the AI agent sandbox holds no API key for the upstream service. On E2B, Daytona and Kubernetes the Endpoint itself still signs in with a Formal machine user API key, held by the Endpoint’s process or a Kubernetes Secret rather than the agent.

How long do cloud agent credentials last?

It depends on the path. The Endpoint refreshes its machine session from the platform’s OIDC token on its own. Federation tokens for Connector access expire at the earlier of the upstream token’s expiry or one hour, and SPIRE JWT-SVIDs last five minutes by default. A Modal Sidecar’s token lives 48 hours, so keep Modal Sandboxes under that. A machine user API key lasts until you rotate it.

Can a cloud agent approve its own access?

Not in the documented setup: approvals run under a different identity from the agent, and the agent’s own identity can’t edit rules or policies. Why the controls sit outside the sandbox shows both pieces.

Does Formal work with Claude Managed Agents?

We haven’t tested it. Claude Managed Agents: what stays on you maps where Formal would sit in Anthropic’s cloud and self-hosted sandboxes, and marks each part as documented or untested.

Product

What happens when the Endpoint can't reach the Connector?

With fail = "closed", as in the Cursor and Devin guides, the matched request fails instead of going out without policy. Requests that no network rule matches pass through untouched, so only the traffic you selected depends on Formal. In Cursor, start the Endpoint from the environment’s terminals, because processes started during install don’t survive the build.

Control what leaves your agent sandboxes

Requests checked inside the sandbox, API keys held on the Connector, and every cloud agent run tied to a person.