How agents run code
When an agent needs to compute something, it does not guess and it does not run code on the Studio services. A coder inside the code-interpreter service writes Python and shell commands and runs them in a sandbox in your account, against files in a workspace in your account. This page describes that path at the component level: which service does what, where files live, how output is bounded, and how one user's work is kept apart from another's. The user's view of the same files, in Folio and in Folio Files in Lens, is in Folio and Files, previews and approvals.
Who this is for
Security engineers and AI engineers who need to know where model-written code runs and what it touches.
Before you start
Two components and one store. agent-runtime runs the conversation or Flow step and decides when code is needed. code-interpreter hosts the coder and dispatches each execution to the Lambda function of the agent's kernel. The workspaces bucket holds every user's files.
The path of one execution
- The agent in
agent-runtimehands the coder a description of the analysis it needs. The coder is a model-driven loop incode-interpreter; its own model calls are metered ascoder_analysis, so the work it does is counted in the run's totals. - The coder writes code and submits an execution. Before it runs, a guard reads what was submitted, the command and the code or script file named with it: ordinary analysis runs at once; code that would delete files outside the coder's scratch directories, write destructively to a database, send messages, or send workspace content to an outside service is held for the user's decision in Studio. The guard reads only what is submitted: a shell command that runs another file already in the project is judged by its command line, not by that file's contents. What holds whatever the code does is the sandbox's own scope (Sandbox isolation).
code-interpreterinvokes the Lambda function of the agent's kernel,alphaagent-env-<environment id>, with the code, the workspace prefix to mirror and the agent's identity. One execution is one invocation.- The handler in the function mirrors the requested project folders down from the workspaces bucket into a fresh working directory, injects the connector variables of the invoking session into the child's environment (one version of each connector that session holds, never another session's), runs the code, uploads only the files the run created or changed, and removes the directory. Its AWS calls run on a session narrowed to this user's prefix and this agent's secret; see Sandbox isolation.
- Standard output and error return to the coder; the coder decides what to do next, and the agent reports the result the code produced. Nothing is cut: output over the coder's limit is saved in full as a file in the workspace, with a preview of its start and end and the path (Output kept in full).
The workspace
Every user has one workspace under users/<user id>/ in the workspaces bucket, and every conversation and every Flow has a project inside it:
users/<user id>/uploads/ files uploaded to Folio, and the person's own folders
users/<user id>/projects/conversations/<conversation>/
inputs/ files attached in the composer
uploaded_files/ composer attachments from before Folio references
from_connectors/ files a connector tool returned, one folder per connector
data/ tables the coder registered
scripts/ code the coder wrote and reuses
outputs/ deliverables
users/<user id>/projects/workflows/<workflow>/
runs/<execution id>/ one project root per run, laid out the same way
inputs/ copies of the run's Folio and S3 inputs, reference_files/ and MANIFEST.json
kept/<execution id>/ copies kept with Keep in Folio, outside run-data retention
team/ the Team folder (governed deployments)
Files a person references. A file referenced in a chat (picked from Folio, attached, named with @, or brought by Start a chat about this run) is not copied into the chat's folder. For each turn, the coder's working directory and the sandbox get it under refs/, read only, at the exact version pinned when the message was sent; refs/ is never written back. The agent reads the same files with read_document("refs/..."). Every path under refs/ is checked to stay inside it. The coder writes only under its own working folder, so a result always lands in the chat's or run's own folder. inputs/, uploaded_files/ and from_connectors/ are mirrored to the coder like the other project folders.
Every file a Flow step writes under outputs/ is a deliverable, whatever its type, attributed to the step that wrote it; outputs/result.json is the run's machine-readable result and is served by name. The handler uploads only what a run created or changed; an upload it could not complete is reported, not dropped: the coder's result names every refused path ("N uploads refused: path: error"), and when nothing landed the run's error output also ends with "[HANDLER] N file(s) could not be uploaded to S3 (...); the run's outputs are incomplete." A run started with an API key writes under users/apikey:<key id>/ and its outputs persist like any other run's.
The workspace is durable and independent of any session: files persist until a user deletes them or a retention rule expires them. Every object Studio writes under a Flow run prefix, whoever started the run, is tagged aa-data-class=run-data at write (objects written before Folio's release are never re-tagged), which is what the workspaces bucket's retention rule keys on; see Data at rest and in transit. Code the coder writes is also kept in the code-scripts bucket so a later turn can reuse it.
Sessions and history
- A coder session is the live state of one conversation's or run's coding work. It expires after four hours of inactivity; losing a session never loses files, because files live in the workspace.
- Each execution is recorded in the
alphaagent-code-executionstable with its truncated output, and expires after 30 days. - The stored record of an execution keeps 50,000 characters of standard output and 10,000 of standard error. It is a history, not the output: the full output is in the workspace (Output kept in full).
Output kept in full
The path from a program to the model never cuts output.
- In the kernel. The handler streams the child's standard output and error into files on the function's own disk as the program runs, so nothing is held in memory. A stream longer than the caller's inline size (50,000 characters for code an agent runs, the coder's own limits below for the coder) is saved in full to the session's result folder under
tool-results/, and the handler returns a preview of its start and end that names the file, with its key, size and line count. Output is kept up toKERNEL_OUTPUT_MAX_BYTES(1 GiB by default, 10 MiB to 8 GiB); every run is held to at most 500 MiB, the largest file the PII sweep reads. Past the ceiling the program is stopped and the result names it. The files are bounded by the function's own ephemeral storage, its Workspace storage, which is not resized for output: if it fills, the program is stopped and the run says so. The upload uses the handler's own session, which writes only under that session's prefix; the child never holds it. - In the coder. Standard output over 30,000 characters and standard error over 8,000 are saved under the step'stool-results/.../coder/folder, with the first and last 2,000 characters and the path in the tool result. The file is on the coder's disk at once, so its own Read and Grep work on it. Its full final message is saved asfinal.md. - In Strands. Every other tool result over 30,000 characters is saved as a file of the chat or run under
tool-results/, and the agent reads it with paged readers that are never cut (Large results and long work).
The coder's own workspace
The coder runs in a task of its own instead of the shared code-interpreter service: one Amazon ECS task on Fargate per coder session, which is one chat, or one Flow step. CODER_IN_KERNEL (Coder in its own workspace) is on by default and can be turned off per deployment.
With it off, the coder stays in the standard workspace, inside the code-interpreter service, without a shell, and runs code through the kernel's Lambda function as described above. No coder task is started and none is kept ready. The same holds for an analysis whose task cannot start, whatever the reason (Fargate capacity or quota, free subnet addresses, the image, or not up within CODER_KERNEL_CLAIM_WAIT_S, 25 seconds): it runs in the standard workspace, code-interpreter logs why, and the run shows a warning, never a failure. A task that starts after its analysis moved on joins the ready ones, or is stopped; it may take up to CODER_KERNEL_START_TIMEOUT_S (360 seconds). After CODER_KERNEL_START_FAILURES_TO_PAUSE (3) failed or late starts within CODER_KERNEL_START_PAUSE_MINUTES (10), no task is started for that long. Ready tasks start CODER_KERNEL_WARM_SETTLE_S (60 seconds) after the service starts, and never while any service on the cluster is mid-deployment, which code-interpreter reads with ecs:ListServices and ecs:DescribeServices on its own cluster; when that cannot be read, none start.
With it on, the coder's worker, its model loop and its shell all run in the task, on the task's own disk. The shell does not run in an operating-system sandbox of its own inside the task: the task is the boundary. What holds it:
| Boundary | How it holds |
|---|---|
| One session per task | A task is bound to one chat or one Flow step the first time it is used and is stopped, never handed on, when that session is done with it. A task kept ready has no session until then. It is stopped after CODER_KERNEL_IDLE_MINUTES (15) with nothing to do and replaced between analyses after CODER_KERNEL_MAX_HOURS (12). A new task reloads from the workspace and the session store. Stop stops the task. |
| Its own disk | The task's disk is the workspace for that session, filled from the chat's or run's prefix: the files the analysis names, the step's own folder and small files at start, and stubs fetched when opened. The shell writes only under the coder's code/ folder; the other project folders are read only. Every write is synced back to the workspaces bucket, so Folio, Lens, retention and the PII sweep are unchanged. |
| Session-scoped credentials | The task definition has no task role. code-interpreter gives each task two sets of temporary credentials from the coder session role, each narrowed by a session policy and renewed within the hour: the worker's reach only that session's prefix in the workspaces bucket, plus the files the run references and the owner's brand kit; the model loop's reach Amazon Bedrock only. No connector secret is ever in the task: run_in_env goes back to code-interpreter, which invokes the kernel with the session's own prefix and connectors. |
| No credentials on disk | The worker, its model loop and the shell all run as the image's non-root user. The task's two credential sets are held only in the memory of the task's agent and the worker, never in a file or in the shell's environment; the shell's model calls go through a gateway in the worker that accepts only Bedrock model calls and signs and meters each one. Approval decisions and kernel results reach the worker as files signed with a per-run key, so one the shell writes is refused. |
| No way in | The tasks' security group admits only the Studio app tasks, on the task agent's port (TCP 8090), never another coder task. |
| A locked-down container | A read-only root file system with only /tmp writable, some Linux capabilities dropped, and the whole task running as a non-root user. The coder's pre-tool hooks fail closed: if one cannot run, the tool call is refused. |
| The command guard | The guard that reads each execution (above) also reads every shell command before it runs. |
| Outbound network | Open: the security group allows all outbound traffic, on any port, through the deployment's egress. This is wider than a kernel's TCP 443. The task can also reach the Studio service ports that the app tasks' group admits from the VPC. |
The task runs its own coder workspace image, not the Studio service image and not the agent's kernel image; a custom kernel image does not change it. The image carries only what the task needs: the task's agent, the coder and its command-line tools. It is about 750 MB compressed, against about 2.5 GB for the service image, so a task goes from start to running in about 30 to 35 seconds instead of about 85. The release builds it with Studio's other images, checks that every tool runs and every Python library imports, and the Organisation copies it into the account's own repository with them.
- The tools, by category. Shell basics; search and structured text (fast file and text search, JSON and YAML, CSV and TSV, XML and HTML, SQL over CSV and Parquet files,
rg,jqandduckdbamong them); archives, zip, 7z and zstd included;curl,wgetandgit; PDF text and image extraction, page rendering, splitting, repair and decryption; OCR in English for scanned pages; image conversion and metadata; GNU parallel; and a Python set for data and documents. A list of every tool, with what each is for, is copied into the coder's own folder for the session and never saved to the chat or run. - How the image is held. Tools fetched from outside a package repository are pinned by checksum, and the build refuses one that does not match. The OCR engine is built from pinned source with the usual hardening (stack protection, fortified functions, full RELRO and position-independent code), and the release's audit reads that from the files. The image converter reads raster images only: its policy refuses PostScript and PDF input, SVG, scripts, text and URLs, so the coder renders PDF pages with the PDF tools instead. No file in the image runs with another user's rights (no set-user-id file).
- Installs for the session. A Python library the image lacks is installed with
piporuvinto a folder under/tmpfor that session, never into the image's own environments, over the task's open outbound network (below). It is gone when the task stops. - Left out on purpose. Office-document conversion, a browser, typesetting and compilers stay in the kernel, where deliverables are made. Leaving them out keeps the image small and the start quick.
Programs that need the kernel's libraries or a connection, and every deliverable, still run in the agent's kernel through run_in_env. The task runs on ARM (Graviton). Default size: 2 vCPU, 8 GiB of memory and 50 GiB of disk (CODER_KERNEL_VCPU, CODER_KERNEL_MEMORY_GIB, CODER_KERNEL_DISK_GIB), with CODER_KERNEL_WARM_POOL (5, up to 50 and at most CODER_KERNEL_MAX_TASKS less 15) tasks started in advance and at most CODER_KERNEL_MAX_TASKS (20) running at once. A claimed ready task is replaced at once; ready tasks start CODER_KERNEL_WARM_STARTS_AT_ONCE (10) at a time, once code-interpreter has been up CODER_KERNEL_WARM_SETTLE_S (60 seconds) and no service on the cluster has been mid-deployment for that long, never on a first use. They never take what an update needs: the account's Fargate vCPU quota less CODER_KERNEL_QUOTA_RESERVE_VCPU (16), less what the services use (an update starts each new task before it stops the old one), less what is running; and the subnets' free addresses less CODER_KERNEL_SUBNET_RESERVE_IPS (64). Short of either, fewer are kept ready, code-interpreter logs a coder-workspaces line and its health check reports it, and an analysis that waited for a cold start says why. An analysis that cannot get a task within CODER_KERNEL_CLAIM_WAIT_S (25 seconds) runs in the standard workspace instead, and the run and the log name the cause (the account's quota, network addresses, AWS throttling, the image, or time); the start goes on and joins the ready tasks. CODER_KERNEL_START_FAILURES_TO_PAUSE (3) real start failures within CODER_KERNEL_START_PAUSE_MINUTES (10) pause new starts for that long; a claim that ran out of the wait does not count. Each task is billed by AWS as Fargate time in your account while it runs (Infrastructure sizing and costs).
A task is often started before the coder needs it. When a chat turn starts with an agent that has the coder, or a Flow run reaches steps whose agents have it, the agent service asks the workspace service for that session's task once, at once, and does not wait for an answer: the request gives up after 2 seconds and never delays the chat or the run. The workspace service sets a ready task aside for the session, tagged aa-state held so it is never counted as ready, or starts one. The task holds no credentials until the session's first analysis binds it. Unclaimed after CODER_KERNEL_PREWARM_HOLD_MINUTES (10), it joins the ready tasks when they want one, or stops. Early tasks count against CODER_KERNEL_MAX_TASKS, the quota and address room, the settle time and the pause exactly as ready ones do; at the cap, a person's own analysis takes a held task or stops an early start, so it is never refused because of one. CODER_KERNEL_WARM_POOL also accepts auto: one ready task for each person on the roster Organisations writes for the deployment, read every 60 seconds, at most CODER_KERNEL_MAX_TASKS less 15, and 5 when the roster is missing, older than 2 hours or unavailable. A number keeps its earlier meaning.
Two more rules apply:
- Settings apply live.
code-interpreterreads the workspace pool settings (CODER_KERNEL_*) again on a short beat and applies them to the tasks without a restart: running analyses finish where they are, new ones follow the new value, and itseffective-configline reports the new values for Organisations to verify. - People removed from the directory. A person absent from a complete roster that Organisations wrote has their tasks stopped and their coder runs cancelled, and each stop is logged. A missing, stale, unavailable or partial roster stops nothing.
Every task is tagged with the code-interpreter task that started it, the deployment, and whether it is ready or in use (aa-owner, aa-deployment, aa-state, with ECS's own cluster and service tags), so its cost can be told apart in AWS Cost Explorer. At start, on every check (CODER_KERNEL_REAP_INTERVAL_S, 30 seconds) and even with the setting off, code-interpreter lists the tasks started for the coder on its cluster and stops any whose owner has stopped. A code-interpreter task that is still draining or stopping during an update keeps its tasks (it stops them itself). An untagged task is stopped only once it is older than CODER_KERNEL_MAX_HOURS (12 hours), so the clean-up never stops a task another code-interpreter is still using. An update still interrupts an analysis in progress, as before: at a stop or restart code-interpreter first ends its open analyses, keeping the files they saved, then stops all of its own tasks at once; ECS gives it up to 120 seconds to do so.
The coder in its task is offered the same tools as in the standard workspace: run_in_env, read_document, connector_fetch, record_fact and the step's search tools (folio_search, folio_open, kg_query, kg_read_node, connector_query, connector_tool), plus the shell. Each search goes back to agent-runtime and runs as the step's own tool, as in the service; its answer reaches the task through the task's agent, which writes it into the run's control folder signed with the run's key, so an answer the shell writes is never taken. An answer longer than CODER_TOOL_RESULT_INLINE_MAX_CHARS (30,000 characters) is saved in full with a preview. A run with a PII policy (a Flow run) is redacted by the same hooks in both places, the shell's output included; a chat carries no policy, in either place. The coder's session is kept in the project's .coder/sessions/ folder in S3, so a later call in the same chat, or one after the task has closed, continues it.
What the coder runs with
- Tools. Read (with page ranges for PDFs), Grep, Glob,
read_document,run_in_env,connector_fetchandrecord_fact, and the shell when it runs in its own task (the shell is refused in the standard workspace).Agentis allowed only for theexplorer(Read, Grep, Glob,read_documentandrun_in_env, no writes, at mostCODER_EXPLORER_MAX_TURNSturns) and thereviewer(reads rendered page images); a pre-tool hook refuses every other agent, fails closed and runs these in the foreground.TodoWritekeeps the checklist Lens shows. Hooks and the approval path apply inside both subagents. - Direct lookups.
folio_search,folio_open,kg_query,kg_read_node,connector_queryandconnector_toolare in-process tools of the coder that hold no credential and no identity. Each call goes back toagent-runtime, which runs it as the step's own tool (list_folio_files,open_folio_file,query_knowledge_base,read_graph_node,query_connectoror the connector's own tool), with the run-as identity of the chat or run, the personal sign-in rules and the run's PII policy. The coder is offered only the tools its step has (CODER_SEARCH_ENABLED, on by default). A result overCODER_TOOL_RESULT_INLINE_MAX_CHARS(30,000) is saved undertool-results/.../coder/with a preview and the path. A connector tool that can change data goes through the step's approval. - Personal data. In a Flow run, a
PostToolUsehook runs the deterministic redaction pass over what Read, Grep, the shell and every coder tool (run_in_env,read_document,connector_fetchand the direct lookups) return, under the run's PII policy, before the coder's model sees it. The preview of long output is redacted before the coder sees it; the saved file itself is covered by the run's sweep of saved results, and what the coder reads back from it passes through the same hook. If redaction fails, the result is withheld and the coder is told why, and the run's activity says "Personal data could not be removed from<what>, so that output was withheld." A chat sends the coder no policy (PII redaction posture). - Results. The coder returns a typed result (summary, files, facts with claim, value, path and locator, limitations, output saved), checked against a schema with up to
CODER_STRUCTURED_RESULT_RETRIES(2) corrections. Facts it records go to.coder/facts.md, which it can read but not write directly and which is given back to it after each compaction, up toCODER_FACTS_MAX_CHARS. - Sessions. Each Flow step forks its own session from the run's base session, so parallel steps never share one. The session store appends part files instead of rewriting the whole session.
- Kernel limits. the
run_in_envdescription and the coder's briefing state, in plain words, how long one run may take (the kernel'stimeout_secondsorCODER_ENV_INVOKE_TIMEOUT_SECONDS, whichever is shorter, rounded down), the kernel's memory, and how much of the coder's working time (CODER_MAX_WALL_MINUTES) is left when the session starts. With no kernel there is no kernel line. One line in the briefing asks the coder to split the work, save partial results as it goes, prefer several runs to one long one when it is close, and never start a run it cannot finish. - Budget.
CODER_MAX_COST_USD(US$25 by default) per analysis, with cache reads at a tenth of the input price, andCODER_MAX_OUTPUT_TOKENS(600,000 by default). Every model call the coder makes, its subagents and its compaction included, is metered ascoder_analysis.
Isolation between users
- A session belongs to the user who started it. A request against another user's session answers 404, the same as a missing session, so identifiers cannot be used to probe.
- Workspace reads are confined to the caller's own prefix in a standard deployment. In a governed deployment every assigned user can read every prefix, and writes still land only in the caller's own folder.
- Each execution runs in its own working directory with its own scoped credentials; two users of the same kernel never share a directory, a home or a credential.
- In a Flow, every run has its own project root,
runs/<execution id>/, under the Flow's project (projects/workflows/<workflow>/); the steps of one run share that root, and no run sees another run's root.
Steps: verify the path in your account
- In Lambda, open the function for one of your kernels and read its recent invocations in CloudWatch Logs: one invocation per execution, each with the working directory it created and removed.
- In S3, open
alphaagent-workspaces-<account>-<region>and browseusers/<your user id>/projects/; the layout above should be visible for any conversation that ran code. - In DynamoDB, open
alphaagent-code-executions: one row per execution, withttlset 30 days out. - On the deployment's Analytics tab in the Organisations console, choose By activity and find Coder analysis (
coder_analysis).
What you should see
- No code execution on any Studio service task: the
code-interpretertask's logs show dispatches, the Lambda logs show the executions. With the coder's own workspace on, its shell commands run in the session'scoder-kerneltask, with that task's logs under/<project>/services/coder-kernel. - Run objects under
runs/<execution id>/carrying theaa-data-classtag.
Limits
- One execution runs for at most its kernel's execution timeout, up to 1,800 seconds (the Lambda maximum). Longer work is split into further executions by the coder: one call into the kernel runs for at most the Coder environment call limit (1,740 seconds by default, a minute below the 1,800-second kernel function timeout) and is then checkpointed and continued in a fresh call. Within each execution a quarter of the remaining time, at least 5 and at most 60 seconds, is kept back for saving results.
- Output is never cut on its way to the model: longer output is saved in full and read from the file (Output kept in full). A kernel stops a program whose output passes
KERNEL_OUTPUT_MAX_BYTES, at most 500 MiB. - The sandbox reaches the network on TCP 443 only (the coder's own task, when it is on, is not limited by port). On a Private deployment it also reaches the internal service ranges an administrator approved, on the approved ports, and nothing else on your network; see Sandbox isolation.
If something goes wrong
- An execution fails at once with a permission error on the workspace: the object key is outside
users/<user id>/; the session policy denies it by design. - A held command never runs: the user did not allow it, or chose to stop the run; the step's card in Studio shows the decision.
- A session "expired": the four-hour inactivity limit passed; the next turn starts a new session and the files are still there.
Build a custom kernel image
For the engineer whose agents need a package or tool the prebuilt image lacks (Kernel). The step-by-step task, building on an AlphaAgent image with your own packages or JARs, is Build a custom kernel image; this section is what any image must carry, for an image built from your own base. The image needs python on its PATH with awslambdaric and boto3 importable, and may carry the handler pair as a fallback (handler.py · aa_env.py, placed next to the Dockerfile):
FROM python:3.12-slim
# awslambdaric 4.1.0 publishes no linux/amd64 wheel; pip would build it from source and fail without cmake
RUN pip install awslambdaric==4.0.4 boto3
COPY handler.py /opt/handler.py
COPY aa_env.py /opt/aa_env.py
The image also needs the openssl command line in /usr/bin, /bin or /usr/local/bin. When the deployment has its own trusted certificate authorities (Deployment detail), the handler uses it so that PostgreSQL (libpq), Node and curl in agent code trust an issuing CA added without its root, as Python does. Without it those three clients need the root CA as well, and the run's certificate error says so. python:3.x-slim carries it already; a bare ubuntu image and AWS's Lambda Python base images do not:
# Debian or Ubuntu
RUN apt-get update && apt-get install -y --no-install-recommends openssl && rm -rf /var/lib/apt/lists/*
# Amazon Linux 2023 (public.ecr.aws/lambda/python:3.12 and later)
RUN dnf install -y openssl && dnf clean all
# Amazon Linux 2 (public.ecr.aws/lambda/python:3.11 and earlier)
RUN yum install -y openssl11 && yum clean all && ln -s /usr/bin/openssl11 /usr/local/bin/openssl
Pin awslambdaric to 4.0.4. Version 4.1.0 (28 September 2026) ships wheels for arm64 only, so on the linux/amd64 build Studio requires pip falls back to the source distribution, which needs cmake and fails on a slim base; an unpinned pip install awslambdaric hits this today. On an Ubuntu base install python-is-python3 (or link /usr/bin/python to python3): the function's entry point runs python, not python3.
The entry point and the delivered handler
An ENTRYPOINT or CMD in the image is not used. Studio configures the function itself: an entry point that is a short Python bootstrap, the command handler.handler and the working directory /opt. On a cold start the bootstrap reads AA_HANDLER_URI, an s3:// prefix in your deployment's storage bucket (agent-management/env-handler/<Studio version>/), downloads the current handler.py and aa_env.py into /tmp/aa_handler, imports the handler from there and starts awslambdaric. A handler fix therefore reaches every kernel, prebuilt or custom, at the Studio upgrade that carries it, with no rebuild: every upgrade points every function at the new prefix and re-probes it. If the download fails (no prefix, a denied or missing object), the bootstrap runs the image's own /opt/handler.py and records why.
Which copy is running is recorded, never silent. The kernel record Studio keeps (as its environments API returns it, not on the kernel's page) carries handler_version, the Studio release the function is configured for, handler_delivery, overlay for the delivered copy or baked for the image's own, and handler_delivery_reason. The function's log opens each cold start with [BOOTSTRAP] handler delivery: overlay uri: s3://..., and when the image's copy is running the coder is told so in its capability summary. In the Lambda console the function shows the entry point override under Image configuration and AA_HANDLER_URI under its variables. The pair served here is the one the current Studio release delivers; handler.py has SHA-256 1cde84e92df03cdf6b0abda4393f6049bc3fe990dac55b91079e423bf4d3b368.
Add the connector drivers whenever agents use Data Bridge connectors: SQLAlchemy with psycopg2-binary (PostgreSQL) or pymysql (MySQL), snowflake-connector-python[pandas] with pyarrow, boto3 for AWS (the prebuilt image carries this set, with fastmcp). A kernel holds no MCP server address or credential, so fastmcp in the sandbox has no connector to call: agents call MCP connectors as tools, through Studio (MCP server):
RUN pip install sqlalchemy psycopg2-binary pymysql 'snowflake-connector-python[pandas]' pyarrow fastmcp httpx requests
Document and media toolkit
Agents produce PDF, PPTX, DOCX and XLSX documents and diagrams and review them visually, which needs system tools. The toolkit installs the exact set from a pinned manifest (alphaagent-env-toolkit.sh · toolkit.lock) on a Debian or Ubuntu base with apt and python3 (python:3.x-slim qualifies).
| Capability | Tools installed |
|---|---|
| Office to PDF, formula recalculation | LibreOffice (soffice) |
| PDF to page images for review | poppler (pdftoppm) |
| Markdown to DOCX and PDF | pandoc |
| Diagrams | Graphviz, Node with @mermaid-js/mermaid-cli (mmdc) and Chromium, pptxgenjs |
| Python document libraries | weasyprint and the libraries the lock's doc-libs check names |
| Fonts | The families the lock's fonts-plex and fonts-raleway checks name |
Place both files next to the Dockerfile and add, before any USER line:
COPY alphaagent-env-toolkit.sh toolkit.lock /opt/alphaagent/toolkit/
RUN chmod 755 /opt/alphaagent/toolkit/alphaagent-env-toolkit.sh && \
/opt/alphaagent/toolkit/alphaagent-env-toolkit.sh
ENV NODE_PATH=/usr/local/lib/node_modules \
PUPPETEER_CACHE_DIR=/opt/puppeteer \
PUPPETEER_EXECUTABLE_PATH=/opt/alphaagent/chrome \
BROWSER_PATH=/opt/alphaagent/chrome-kaleido
BROWSER_PATH must point at /opt/alphaagent/chrome-kaleido, the launcher the toolkit writes with the flags Chromium needs in the sandbox, not at the Chromium binary. The installer is idempotent; --apt-only, --pip-only, --npm-only, --fonts-only and --no-fonts split it across layers. It writes /opt/alphaagent/toolkit.lock, which Studio reads as the image's toolkit version.
Build, verify and push
Replace <region> and <ecr-registry> (for example 123456789012.dkr.ecr.<region>.amazonaws.com); the repository is the deployment's environment repository, which the Create kernel form names when you choose Custom image.
aws ecr get-login-password --region <region> | docker login --username AWS --password-stdin <ecr-registry>
docker buildx build \
--platform linux/amd64 \
--provenance=false --sbom=false \
-t <ecr-registry>/<repository>:my-agent-env-1.0 \
--push .
Run the toolkit's checks the way the sandbox runs: a non-root user that is not the image's own, a read-only root filesystem, only /tmp writable:
docker run --rm --platform linux/amd64 --user 993:990 --read-only --tmpfs /tmp:size=512m \
-e HOME=/home/agent -e AA_TOOLKIT_FORCE_BROWSER_CHECKS=1 \
<ecr-registry>/<repository>:my-agent-env-1.0 \
/opt/alphaagent/toolkit/alphaagent-env-toolkit.sh --check --lambda-like
The last stdout line is a JSON summary whose ok is true only when every check passed; the exit code follows it. --check alone runs as the invoking user without the sandbox conditions. On an Apple silicon Mac the two browser checks are skipped under emulation unless AA_TOOLKIT_FORCE_BROWSER_CHECKS=1 is set; run the gate once on a native amd64 machine. Then, in Studio under Kernel, choose Create kernel, set Image source to Custom image, choose Refresh images and pick the image under Image URI.
On the Python and Java image
When agents call Java libraries from Python, build your image on the prebuilt AlphaAgent Python and Java image instead of a plain Python base. It already carries a Java 21 runtime (JAVA_HOME=/opt/java/openjdk, java on the PATH), JPype, everything in AlphaAgent Python, the delivered handler and the document toolkit, so you add only your own JARs and Python libraries. Its tag in your deployment's environment repository is alphaagent-python-3.12-java-21, and Create kernel offers it under Prebuilt kernel.
Place your JARs in a jars/ directory and your Python requirements in requirements.txt next to the Dockerfile:
FROM <ecr-registry>/<repository>:alphaagent-python-3.12-java-21
# The base ends as the unprivileged agent user; installing needs root.
USER root
COPY jars/ /opt/myorg/jars/
COPY requirements.txt /tmp/requirements.txt
RUN pip install --no-cache-dir -r /tmp/requirements.txt && pip check \
&& chmod -R a+rX /opt/myorg
USER agent
Do not repeat the awslambdaric, handler or openssl steps: the base has them. Pin your Python libraries to exact versions, and use wheels for Python 3.12 on Linux amd64.
From Python, start the JVM once with your JARs on the class path, then call into them:
import jpype
import jpype.imports
jpype.startJVM(classpath=["/opt/myorg/jars/*"])
from com.example.pricing import Curve # a class in your JAR
print(Curve.of([1.0, 2.0]).total())
The sample JAR shows the same shape: jpype.startJVM(classpath=["/opt/alphaagent/java/alphaagent-sample.jar"]), then from com.alphaagent.sample import Greeter. A JVM can be started once per process, so start it with every JAR the code needs.
Build, check and push as above, with your own tag. To check the Java side the way the sandbox runs it, run the image's smoke script in the same conditions; its last stdout line is a JSON summary whose ok is true when Java starts and JPype can call the sample JAR:
docker run --rm --platform linux/amd64 --user 993:990 --read-only --tmpfs /tmp:size=512m \
-e HOME=/home/agent \
<ecr-registry>/<repository>:my-java-env-1.0 \
python /opt/alphaagent/java/java_smoke.py
Then create a kernel with Image source set to Custom image and pick the image. The same limits apply: under 4.0 GB compressed and up to 1,800 seconds per run. Put every JAR in the image: nothing is fetched at run time. A custom image is shared through a Library by digest like any other kernel.