Sandbox isolation
Code that an agent writes runs in AWS Lambda inside your account, never in the Studio services themselves. This page describes the boundaries around one execution: the function it runs in, the working directory and home it gets, how the handler keeps its own credentials away from the code, the per-invocation AWS credentials that are narrowed to one user's files and one agent's secret, and what the code can and cannot reach.
Who this is for
Security engineers assessing what untrusted, model-written code can do inside your account.
Before you start
Two terms. A kernel is the execution environment your users choose for an agent: a container image (a prebuilt one or a custom one) and the resources each run gets. An execution is one run of a script or shell command that the coder submits. Kernels are managed in Studio under Kernel; see Kernel.
One function per kernel, one invocation per execution
agent-management creates one Lambda function per kernel, alphaagent-env-<environment id>, from the kernel's image in your alphaagent-envs repository, placed in the deployment's private subnets on the sandbox security group. Each execution is one invocation of that function: the code-interpreter service sends the code, the workspace prefix to mirror and the agent's identity, and the handler inside the function does the rest.
A warm Lambda container may serve several invocations in a row, for different agents and different users of the same kernel. Everything below exists so that one invocation cannot leave anything for the next one to find.
Fresh working directory
Every execution runs in a new directory under /tmp, created with mkdtemp and mode 0700, named /tmp/.aa-work-<random>. The handler mirrors the requested project folders down from the workspaces bucket into it, runs the code with that directory as the current directory, uploads only the files the run created or changed, and removes the directory. There is no predictable path that survives between executions, so code cannot plant a file where a later user's code would import it.
Downloads are served from a per-project cache whose index lives only in the handler's memory; every cache hit is re-verified by SHA-256 before it is hard-linked into the working directory, and anything in the cache the index does not vouch for is removed.
Private home per scope
The child process gets its own HOME, /tmp/home-<hash of scope>, where the scope is the invoking agent, else the owning user, else the execution itself. The same agent's later executions on the same warm container find what it installed with pip install --user; a different agent never does. This closes the path where one user's code writes a startup hook (usercustomize.py, a .pth file, a pip.conf or a shell rc file) that the next user's code would execute.
Re-execution with a clean environment
Lambda hands a function its IAM role credentials as environment variables, and a child process can normally read its parent's starting environment from /proc/<ppid>/environ. The handler prevents this in two ways at import time:
- It reads its credentials, removes them from the environment, passes them to itself over a pipe, and re-executes itself (
execve) with an environment that carries none. The credentials exist only in the serving process's memory. - It re-executes from an exec-only copy of the interpreter, which makes the serving process non-dumpable from its first instruction. A same-user child that tries to open
/proc/<ppid>/environ,/proc/<ppid>/memor/proc/<ppid>/mapsgetsPermissionError.
The handler records the outcome of both measures in its capability probe, so the service can see when a container did not achieve them.
Per-invocation credentials, narrowed by a session policy
Two IAM roles are involved, both created by the core stack:
- The Lambda execution role holds no data permissions. It can start the function (pull the image, create network interfaces, write its own logs, read the staged handler from one prefix of the overflow bucket) and it can assume one role: the sandbox scoped role.
- The sandbox scoped role is trusted only by the execution role. Its policy allows reads and writes on the workspaces bucket and
secretsmanager:GetSecretValueon secrets namedalphaagent-connector-creds-*. Nothing else.
The handler never uses the scoped role's full policy. Every AssumeRole it makes carries a session policy that narrows the session to this invocation: read on users/<user id>/ (plus a deployment-wide read prefix in a governed deployment), write on users/<user id>/ only, ListBucket conditioned on the same prefixes, and read of the one secret alphaagent-connector-creds-<agent id> for the invoking agent. The effective permission is the intersection of the role's policy and the session policy, so no session can reach another user's files or another agent's secret. Sessions last at most 3600 seconds and are minted per invocation.
Every session policy also carries one Deny: no s3:GetObject or s3:GetObjectVersion on any workspaces object tagged aa-personal-owner with another person's user id. Studio puts that tag on every object it writes from a connector result fetched with a person's own sign-in: the file, its .txt text copy, the saved result, text caches, preview renders, kept copies and run copies. So in a governed deployment, where a session may read other users' prefixes, a colleague's code can at most see such a file's name in a listing, never its content. In a governed deployment the read prefixes also include team/, the Team folder; a standard deployment never reads it. The scoped role reads exact object versions (s3:GetObjectVersion), which is how a file a person referenced is read at the version pinned when the message was sent.
The child process that runs your agent's code receives none of these credentials. Its environment is the image's own plus this invocation's connector variables; see Secrets and connector credentials.
What an agent's code can reach
| Reachable | How |
|---|---|
| The files of its own conversation or run | Mirrored into the working directory by the handler; changes are uploaded back to users/<user id>/... |
| The files the person referenced | Downloaded by version into refs/, read only, before the code runs; nothing under refs/ is ever uploaded, and every path is checked to stay inside refs/ |
| The connectors of its own session | CONN_<connector id>_* variables in the child's environment, resolved at invocation: one version of each connector the invoking conversation or run holds, never another session's. An MCP connector contributes only its type and name; its tools are called by Studio, outside the sandbox (Secrets and connector credentials) |
| The public internet | Outbound TCP 443, through AlphaAgent's NAT gateway or your Transit Gateway and firewall |
| Your internal services (private deployments) | TCP 443 and the approved ports, only to the internal service ranges an administrator approved, over your Transit Gateway; every other private range is not routed (with outbound traffic through your Transit Gateway it is dropped inside the VPC) |
| Your own certificate authorities | When the deployment has trusted certificate authorities, the child's SSL_CERT_FILE, REQUESTS_CA_BUNDLE, CURL_CA_BUNDLE and NODE_EXTRA_CA_CERTS point at the public roots plus them, in that execution's own directory; AWS calls in agent code keep the public roots |
| Packages | Those in the kernel's image; code in a kernel does not install packages at run time |
What an agent's code cannot reach
| Not reachable | Why |
|---|---|
| The handler's AWS credentials | Removed from the environment before the child exists; the serving process is non-dumpable |
| Other users' workspace files | Not mirrored; the session policy denies the prefix (a governed deployment allows reads, except of another person's personal-sign-in files, which the Deny above refuses) |
| Other agents' connector secrets, service configuration secrets, the licence secret | The scoped role reads only alphaagent-connector-creds-*, and the session policy narrows that to one secret |
| The ECS task roles, Bedrock, DynamoDB tables | The child has no AWS credentials at all |
| A previous execution's working directory | Removed after each execution |
| Ports other than 443 | Security group egress, except the approved ports to the approved internal ranges |
| Your network outside the approved ranges, the deployment's own VPC range | Not routed; on a private deployment only the listed ranges have a route to your Transit Gateway |
One bound the design states plainly: every child of a warm container is the same operating-system user on the same /tmp, so a background process that one execution leaves behind is not stopped by these measures. The Lambda timeout ends the invocation.
The coder's own workspace
Everything above describes code that runs through a kernel's Lambda function. The coder also runs in a Fargate task of its own for each chat or Flow step, where it works on its own disk and has a shell (CODER_IN_KERNEL, Coder in its own workspace). It is on by default. With it turned off, or for an analysis whose task cannot start, the coder runs in the shared code-interpreter service without a shell, and everything it runs goes through the kernel as above.
When it is on, that task is a different boundary. The shell does not run in an operating-system sandbox of its own inside the task; the task itself is the boundary: one session per task, never shared; no task role, and credentials that reach only that session's prefix; a task that runs as a non-root user, with its credentials held only in memory, never on disk or in the shell's environment; no inbound traffic except from the Studio app tasks, and none between coder tasks; a read-only root file system; and the command guard on every shell command. Outbound traffic is open on every port, which is wider than a kernel's TCP 443. The task runs its own coder workspace image, and the coder may install a Python library that image lacks: into a folder under /tmp for that session only, never into the image's own environments, and gone when the task stops. The full list is on How agents run code.
A kernel also no longer holds a program's output in the function's memory: output is written to files on the function's own disk as it runs and saved to the session's result folder, up to KERNEL_OUTPUT_MAX_BYTES (1 GiB by default, and a run is held to at most 500 MiB). The function's ephemeral storage is the kernel's Workspace storage and is not resized for output; a program that fills it is stopped. The handler's session still writes only under the invoking user's prefix, and its credentials still never reach the child.
Steps: verify the boundaries in your account
- In IAM, open
alphaagent-<stack environment>-lambda-execution-role, where the middle segment is the core stack'sEnvironmentparameter (prodby default), not a kernel. Its inline policy should containsts:AssumeRoleon the sandbox scoped role,s3:GetObjecton one handler prefix, logs, network interface and ECR read actions, and nothing on your data. - Open
alphaagent-<stack environment>-sandbox-scoped-role. Its trust policy names only the execution role; its policy covers the workspaces bucket andalphaagent-connector-creds-*. - In Lambda, open any
alphaagent-env-*function. Under Configuration, the environment variables holdAA_HANDLER_URI(the storage prefix the current handler is downloaded from) and no credential and noCONN_variable; Image configuration shows the entry point Studio set (a Python bootstrap), the commandhandler.handlerand the working directory/opt; VPC shows the private subnets and the sandbox security group. - In EC2, open that security group. Outbound: TCP 443 to
0.0.0.0/0, plus on a private deployment one rule per approved internal range and port. Inbound: none. - If CloudTrail is enabled, filter
AssumeRoleevents for the scoped role. Each carries a session policy and a session name derived from the invocation.
What you should see
- No
alphaagent-env-*function with credentials or connector values in its configuration. - Every sandbox
AssumeRoleevent showsDurationSecondsof at most 3600 and a policy document. - Sandbox log groups (
/aws/lambda/alphaagent-env-*) carry handler messages, including "credential isolation: re-executing with a clean environment".
Limits
- An invocation runs for at most its kernel's execution timeout, up to 1,800 seconds (the Lambda maximum); memory from 1,769 MB up to 10,240 MB and ephemeral storage between 2,048 MB and 10,240 MB, set per kernel on Create kernel and changed with Edit resource budget. AWS limits Lambda memory on newer accounts: Studio sends the value and AWS decides, and a refusal is shown with the steps for your AWS administrator.
- To learn that limit (no AWS API reports it), agent-management creates a function named
alphaagent-env-memory-probeat 10,240 MB with the kernels' own execution role and no network configuration, never runs it, and deletes it once AWS has answered: when the service starts, again while the account is limited, and after AWS refuses a kernel's memory. Organisations runs the same check, asalphaagent-org-kernel-memory-check, when it installs or upgrades the deployment and when an administrator clicks Check again. Both show in AWS CloudTrail asCreateFunctionandDeleteFunction. - Egress is TCP 443, plus the approved ports to the approved internal ranges. A data source on another port, or outside the ranges, is not reachable from a sandbox; an administrator adds a range or port under Network on the deployment's Overview.
- The measures above are process boundaries inside one Lambda container, not separate containers per user.
If something goes wrong
- An execution fails with an access error on
PutObject: the handler tags every object it writes under a run prefix, and the scoped role must allowPutObjectTagging; a service control policy that removes it breaks uploads. - An execution cannot reach a data source: for a public source, check that it accepts TCP 443 from the NAT gateway's Elastic IP or your firewall's egress addresses, and that your firewall allows it; for an internal one, that its range and port are approved on the deployment and your network routes back to the deployment's VPC range. A certificate from your own CA needs it under Trusted certificate authorities.
- The capability probe reports
non_dumpable: false: the container could not re-execute from the exec-only copy; the handler logs why. Raise it with us with the log line.