Skip to main content
Version: Studio 2.2.7

Build a custom kernel image

For the engineer who builds the image a kernel runs, when agents need a Python package, a Java library (JAR) or a tool that the prebuilt images do not carry. Agents cannot install packages while they run: what code can import is exactly what the kernel's image carries, so anything extra goes into a custom image. You build it once, push it to your deployment's environment repository, create a kernel from it, and share that kernel with your organisation.

Before you start, have:

  • Docker with buildx, on a Mac or Linux machine.
  • The AWS CLI signed in to the AWS account and region of your Studio deployment, with the permissions below.
  • The packages or JARs your agents need, with exact versions.

Choose a base image​

Build on one of the two AlphaAgent images unless you have a reason not to. They already carry everything Studio needs to run code, the database and Snowflake drivers and the MCP client that Data Bridge connectors use in code, and the tools agents use to produce PDF, Word, PowerPoint and Excel documents and diagrams, so you add only your own libraries.

BaseTag in your environment repositoryChoose it to
AlphaAgent Pythonalphaagent-python-3.12Add Python packages
AlphaAgent Python and Javaalphaagent-python-3.12-java-21Add Java libraries that Python code calls through JPype, with or without Python packages
Your own Linux Python imageAny, such as python:3.12-slimStart from nothing. You then add the execution handler, its Python packages, openssl, the connector drivers and the document toolkit yourself (How agents run code)

Each Studio upgrade refreshes the two AlphaAgent tags in your repository, so a rebuild after an upgrade picks up the current base.

Find your environment repository​

Every Studio deployment has one environment repository in Amazon Elastic Container Registry (ECR), in the deployment's own account and region. It is named alphaagent-envs, so its address is:

<account-id>.dkr.ecr.<region>.amazonaws.com/alphaagent-envs

for example 123456789012.dkr.ecr.eu-west-2.amazonaws.com/alphaagent-envs. In Studio, Kernel, Create kernel, Image source Custom image lists the images in it as alphaagent-envs:<tag>, and when it lists none the Image URI field reads "Tag in" followed by the repository's address. The repository already holds the two AlphaAgent tags above. ECR scans each image you push to it for known vulnerabilities; the findings are on the image in the ECR console.

AWS permissions​

The person or role that builds the image needs, in the deployment's account:

PermissionWhy
ecr:GetAuthorizationToken (resource *)Sign Docker in to ECR
ecr:BatchGetImage, ecr:GetDownloadUrlForLayerPull the AlphaAgent base image
ecr:BatchCheckLayerAvailability, ecr:InitiateLayerUpload, ecr:UploadLayerPart, ecr:CompleteLayerUpload, ecr:PutImagePush your image
ecr:DescribeImages (optional)Read your image's size and digest

Scope every permission except the first to the repository, for example:

{
"Version": "2012-10-17",
"Statement": [
{"Effect": "Allow", "Action": "ecr:GetAuthorizationToken", "Resource": "*"},
{"Effect": "Allow",
"Action": ["ecr:BatchGetImage", "ecr:GetDownloadUrlForLayer", "ecr:BatchCheckLayerAvailability",
"ecr:InitiateLayerUpload", "ecr:UploadLayerPart", "ecr:CompleteLayerUpload",
"ecr:PutImage", "ecr:DescribeImages"],
"Resource": "arn:aws:ecr:<region>:<account-id>:repository/alphaagent-envs"}
]
}

Add Python packages​

  1. Create a folder with a requirements.txt that pins each package to an exact version, for example tabulate==0.9.0. Use packages that publish wheels for Python 3.12 on Linux amd64.

  2. Add a Dockerfile next to it:

    FROM <account-id>.dkr.ecr.<region>.amazonaws.com/alphaagent-envs:alphaagent-python-3.12

    # The base ends as the unprivileged agent user; installing needs root.
    USER root

    COPY requirements.txt /tmp/requirements.txt
    RUN pip install --no-cache-dir -r /tmp/requirements.txt && pip check

    USER agent

pip check stops the build if a package you add conflicts with one the base carries.

Add Java libraries​

  1. Create a folder with your JARs in jars/, and a requirements.txt for any Python packages (it may be empty).

  2. Add a Dockerfile next to them:

    FROM <account-id>.dkr.ecr.<region>.amazonaws.com/alphaagent-envs: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

Put every JAR the code needs in the image, including the JARs your own JARs depend on: nothing is downloaded while code runs. Agent code starts the JVM once, with every JAR on the class path, and then calls 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 base carries a Java 21 runtime (JAVA_HOME=/opt/java/openjdk), so compile your JARs for Java 21 or earlier. A JVM can be started only once per process, so start it with all the JARs together. Say in the agent's instructions where the JARs are and which classes to use.

Build and push​

From the folder, sign Docker in to ECR and build for Linux amd64, giving each build a new tag:

aws ecr get-login-password --region <region> | \
docker login --username AWS --password-stdin <account-id>.dkr.ecr.<region>.amazonaws.com

docker buildx build \
--platform linux/amd64 \
--provenance=false --sbom=false \
-t <account-id>.dkr.ecr.<region>.amazonaws.com/alphaagent-envs:pricing-java-1.0 \
--push .

The three flags matter: kernels run on Linux amd64 and accept a single-platform image, so an image built without --platform linux/amd64, or with the provenance and SBOM attestations Docker adds by default, is refused when you create the kernel. On an Apple silicon Mac, Docker builds the amd64 image under emulation, which takes longer. The image must be under 4.0 GB compressed; the AlphaAgent bases are about 1.2 GB.

Check the image​

Run the image the way the sandbox runs it, as a user that is not the image's own, with a read-only root filesystem and only /tmp writable, and import what you added:

IMAGE=<account-id>.dkr.ecr.<region>.amazonaws.com/alphaagent-envs:pricing-java-1.0

docker run --rm --platform linux/amd64 --user 993:990 --read-only --tmpfs /tmp:size=512m \
-e HOME=/tmp/home "$IMAGE" \
sh -c 'mkdir -p "$HOME" && python -c "import tabulate; print(tabulate.__version__)"'

For the Python and Java base, also run its smoke script; its last 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=/tmp/home "$IMAGE" python /opt/alphaagent/java/java_smoke.py

Then call one of your own classes the same way, with python -c and the JPype lines above.

Create the kernel and try it​

  1. In Studio, open Kernel, click Create kernel, enter a Name such as "Pricing with Java", and set Image source to Custom image.

  2. Click Refresh images and choose your image under Image URI, for example alphaagent-envs:pricing-java-1.0.

  3. Set the Resource budget (Kernel) and click Create kernel. Wait for Active; the first provisioning of a new image can take up to 15 minutes.

  4. Set the kernel on an agent version and activate it (Agents: configure and activate).

  5. In Studio Chat, ask that agent to run a check, for example:

    Use JPype to start the JVM with the class path /opt/myorg/jars/*, import Curve from com.example.pricing, and print Curve.of([1.0, 2.0]).total(). Do not install any packages. If a step fails, show the exact error.

The agent runs the code in the kernel and reports what it printed. On the kernel's page, Image digest (pinned at provision) is the image the kernel runs.

Update the image​

A kernel keeps the image it was provisioned with: it is pinned by digest, so pushing a new image, even under the same tag, does not change a running kernel. To give agents a new version of your libraries:

  1. Build and push the image with a new tag, for example pricing-java-1.1, and check it.
  2. Create a new kernel from it, as above.
  3. For each agent: click Create new version, then Configure and activate, remove the old kernel from Selected resources, click Set kernel, choose the new kernel, and activate the version (Agents: configure and activate).
  4. When the old kernel's Kernel map shows no agents, delete it (Kernel).

You do not rebuild for Studio's own fixes to how code runs: Studio delivers them to every kernel, custom ones included, at each upgrade. Rebuild when the kernel's page reads "The image’s toolkit is behind the current handler. Rebuild from the guide’s handler.py to pick up fixes.", or when you want the current AlphaAgent base after an upgrade.

Share the kernel across your organisation​

On the kernel's page, click Share and choose an Organisation Library (Kernel). The Library copy carries the image and the resource budget; your JARs and packages travel inside the image.

  • In the same Studio, a person who takes the copy gets a kernel on the same image. In a governed deployment everyone already shares each kernel.
  • In another Studio of your organisation, when someone takes the copy, Organisations copies your image from this deployment's environment repository into the other deployment's, so nobody pushes it twice. A custom image over 4 GB cannot be shared. A kernel on a prebuilt image uses the other Studio's own copy of that image.

Whoever takes the copy ticks Provision now, or provisions it later from Kernel.

If something fails​

You seeCheck
"Custom images must be in this deployment’s environment repository (repository). Push your image there and choose it from the list."The image is in alphaagent-envs in this deployment's account and region (Find your environment repository).
"Build with --platform linux/amd64 --provenance=false --sbom=false."Rebuild with the three flags (Build and push).
"environments accept images up to 4.0 GB"Remove what agents do not need, or split the libraries across two kernels.
"No images found. Push an image, then choose Refresh images."The push finished in this deployment's account and region; then click Refresh images.
docker push is deniedThe permissions, and that Docker signed in to the same account and region.
Needs attention, "The image does not implement the AlphaAgent handler contract: …"The image is built on an AlphaAgent base, or carries what How agents run code lists.
In chat, ModuleNotFoundError or a Java class that cannot be foundThe agent uses the new kernel, the package or JAR is in the image (Check the image), and the JVM was started with every JAR on the class path.