All Products
Search
Document Center

Agent Sandbox:Mount an AgenticBucket Volume

Last Updated:Oct 13, 2026

When you create a Sandbox, use volume_mounts to mount an existing AgenticBucket Volume by name.

How it works

After the volume is mounted, the Sandbox can access the BucketSpace through file paths, and the data is not deleted when the Sandbox is released.

The AgenticBucket must be created in advance. The BucketSpace does not need to be created in advance. If the BucketSpace does not exist on the first mount, the system creates it automatically.

To append a mount to a running Sandbox, see Append a volume mount.

Prerequisites

  • You have created an AgenticBucket Volume for the target team and obtained the volume name.

  • You have prepared an Agent Sandbox API key that is bound to the same team. A volume and an API key cannot be used across teams. For more information, see Create an API Key.

  • You have prepared a Resource Access Management (RAM) role with read and write permissions on the target AgenticBucket and BucketSpace. The trust policy of the role allows the Function Compute service to assume the role. For more information, see Configure a RAM role.

  • You have prepared the Agent Sandbox API URL, the domain, and an available template.

You do not need to disable BlockPublicAccess for the AgenticBucket. The Sandbox obtains Security Token Service (STS) temporary credentials through the RAM role. You do not need to configure a long-term AccessKey ID (AK) or AccessKey secret (SK) in the metadata or in code.

If you use a custom template of the second-generation runtime (MicroVM), the source image must have ossfs2 2.0.9 or later pre-installed.

Procedure

Step 1: Prepare the second-generation runtime image

This step applies only if you use a custom template of the second-generation runtime (MicroVM). If you already have a template that meets the requirements, skip this step and go to Step 2: Install the SDK.

If you use a custom template of the second-generation runtime (MicroVM), you must pre-install ossfs2 2.0.9 or later in the source image before you build the template. The second-generation runtime uses the source image directly and does not inject ossfs2 when the template is built. ossfs2 2.0.x installation packages support only linux/amd64. The following Dockerfile uses Ubuntu 22.04 and ossfs2 2.0.9 as an example:

FROM ubuntu:22.04

ARG DEBIAN_FRONTEND=noninteractive
ARG OSSFS2_DEB_URL=https://gosspublic.alicdn.com/ossfs/ossfs2_2.0.9_linux_x86_64.deb
ARG OSSFS2_DEB_SHA256=33b5d16e870f53680a595b6369fd34eda18928807bae5fd934940f079cc04f6e

RUN set -eux; \
    apt-get update; \
    apt-get install -y --no-install-recommends ca-certificates curl fuse3; \
    curl --fail --location --retry 3 \
        "${OSSFS2_DEB_URL}" \
        --output /tmp/ossfs2.deb; \
    echo "${OSSFS2_DEB_SHA256}  /tmp/ossfs2.deb" | sha256sum -c -; \
    apt-get install -y --no-install-recommends /tmp/ossfs2.deb; \
    rm -f /tmp/ossfs2.deb; \
    rm -rf /var/lib/apt/lists/*

WORKDIR /root

When you upgrade the installation package, update both OSSFS2_DEB_URL and OSSFS2_DEB_SHA256. Do not skip the SHA-256 verification, and do not write storage credentials or mount configurations into the image.

Before you build and push the linux/amd64 image, replace the placeholders with actual values:

docker buildx build \
  --platform linux/amd64 \
  --push \
  -t <REGISTRY>/<NAMESPACE>/microsandbox-ossfs2:2.0.9 \
  .

After the build is complete, verify that the ossfs2 version in the image is 2.0.9 or later:

docker run --rm --platform linux/amd64 \
  <REGISTRY>/<NAMESPACE>/microsandbox-ossfs2:2.0.9 \
  sh -euxc '
    test -x /usr/local/bin/ossfs2
    installed_version="$(dpkg-query -W ossfs2 | cut -f2)"
    dpkg --compare-versions "${installed_version}" ge "2.0.9"
  '

This check verifies only the image content. It does not mean that the permissions, the endpoint, or the actual mount operation works.

Step 2: Install the SDK

This topic uses the E2B Python SDK as an example. volume_mounts requires E2B Python SDK 2.31.0 or later.

python3 -m venv .venv
source .venv/bin/activate
pip install e2b==2.31.0

Step 3: Mount and verify

Environment variables

Environment variable

Purpose

Source or value

E2B_API_KEY

The API key used to access Agent Sandbox.

Obtain the key in the Agent Sandbox console. The key must be bound to the team that owns the volume.

E2B_API_URL

The endpoint of the E2B API.

Set the value to https://api.<REGION>.sandbox.aliyuncs.com. Use the same region as the target volume.

E2B_DOMAIN

The service domain that the SDK uses.

Set the value to <REGION>.sandbox.aliyuncs.com. Use the same region as the API endpoint, and exclude the protocol prefix.

E2B_TEMPLATE

The template used to create the Sandbox.

Specify the ID or alias of an available template that meets the requirements described in Prerequisites of this topic. Obtain the value in the Agent Sandbox console.

AGENTIC_BUCKET_VOLUME_NAME

The name of the AgenticBucket Volume to mount.

Use the name that you set when you created the AgenticBucket Volume, or query the name in the volume list. Do not use the volume ID.

Mount example

Set the following parameters in your terminal and replace the placeholders with actual values. For the value of each variable, see Environment variables in this topic.

export E2B_API_KEY="<YOUR-E2B-API-KEY>"
export E2B_API_URL="https://api.<REGION>.sandbox.aliyuncs.com"
export E2B_DOMAIN="<REGION>.sandbox.aliyuncs.com"
export E2B_TEMPLATE="<TEMPLATE-ID>"

export AGENTIC_BUCKET_VOLUME_NAME="<VOLUME-NAME>"

The local mount directory resides in the Sandbox and corresponds to the key of volume_mounts. Use a subdirectory of /home, /mnt, /tmp, or /data. This topic uses /mnt/agentic-bucket.

The following example reuses the mountConfig.role of the volume to mount the AgenticBucket Volume to /mnt/agentic-bucket. Make sure that the volume stores a valid RAM role.

The example creates a separate test file with a random identifier in the mount directory, writes data to the file, and reads the file for verification. It then deletes the file and releases the Sandbox created in this run. Use a mount configuration that provides read and write permissions.

Save the following code as 03_mount_agentic_bucket_volume.py:

import os
from uuid import uuid4

from e2b import Sandbox


def require_env(name: str) -> str:
    value = os.environ.get(name, "").strip()
    if not value:
        raise RuntimeError(f"Missing environment variable: {name}")
    return value


mount_dir = "/mnt/agentic-bucket"
marker_path = f"{mount_dir}/hello-agentic-bucket-{uuid4().hex}.txt"
sandbox = None
marker_written = False

try:
    sandbox = Sandbox.create(
        template=require_env("E2B_TEMPLATE"),
        timeout=300,
        api_key=require_env("E2B_API_KEY"),
        api_url=require_env("E2B_API_URL"),
        domain=require_env("E2B_DOMAIN"),
        volume_mounts={
            mount_dir: require_env("AGENTIC_BUCKET_VOLUME_NAME"),
        }
    )

    sandbox.files.write(marker_path, "hello agentic bucket\n")
    marker_written = True
    content = sandbox.files.read(marker_path)
    if content != "hello agentic bucket\n":
        raise RuntimeError(f"File content mismatch: {content!r}")
finally:
    try:
        if sandbox is not None and marker_written:
            sandbox.files.remove(marker_path)
    finally:
        if sandbox is not None:
            sandbox.kill()

print("AgenticBucket Volume mount read/write verification succeeded")

Run the example:

python 03_mount_agentic_bucket_volume.py

If the output shows AgenticBucket Volume mount read/write verification succeeded, the read and write operations, the test file cleanup, and the Sandbox release are complete.

Behavior notes

  • volume_mounts uses the {mount directory: volume name} format. Do not use a volume ID.

  • When you create a Sandbox, reuse the RAM role stored in the volume or specify a role in the metadata. For information about the priority, see Configure a RAM role. You do not need to configure long-term AK/SK in the Sandbox.

  • When you resume a paused Sandbox, the volume mount is restored.

  • Releasing a Sandbox does not delete the data in the BucketSpace. The example deletes the test file. The retention and cleanup of other data must be handled separately.

  • A read-only volume allows only read operations on the files in the mount directory.

Limits

  • In the same Sandbox, AgenticBucket supports a maximum of 5 mount points. The count includes mounts created with the Sandbox and mounts appended later, and also includes mounts that specify the storage configuration directly.

  • The mount directory must be a normalized absolute Unix path. It cannot be /, and it cannot contain leading or trailing spaces, repeated path separators, or the . or .. path segments.

  • The mount directory cannot be a system directory such as /bin, /opt, /var, or /dev, or a subdirectory of one. It also cannot contain a hidden directory, such as .cache, whose name starts with ..

  • Mount directories cannot be duplicated in the same Sandbox.

FAQ

The system reports that the volume cannot be found

If the error message is volume not found, check the volume name in the request, the team that owns the API key, and the region of the API endpoint. When you mount a volume by name, use an existing volume in the same team. Do not specify a volume ID.

The volume exists, but the system reports that it is unavailable

If the error message contains is not available, the volume exists, but its status does not meet the mount requirements. Query the status and the status reason of the volume by using GetVolume, and mount the volume only after you confirm that it is available. If a failure reason exists, resolve it first. Submitting the mount request again does not make the volume available.

Sandbox creation reports a missing RAM role

If the error message contains AgenticBucket mount requires Function role, the Sandbox creation request did not obtain the RAM role required for the mount.

The example in this topic reads the role from the mountConfig.role of the volume. If the metadata of the creation request explicitly sets fc.sandbox.auth.role, the metadata takes precedence. Check the role configuration actually used, specify a valid Alibaba Cloud Resource Name (ARN) for the role, and then submit the creation request again. For information about how to configure the role, see Configure a RAM role.

The mount fails when the Sandbox is created

Based on the error message, check the endpoint and the full names of the AgenticBucket and BucketSpace stored in the volume. If the message indicates that access to the storage is denied, check the RAM role that the Sandbox actually uses and the access control of the AgenticBucket. For information about how the role is selected, see Configure a RAM role.

If you use a custom template of the second-generation runtime, also verify that ossfs2 is installed as described in Step 1: Prepare the second-generation runtime image in this topic.

The volume is mounted, but write operations fail

First, check whether the volume is configured with readOnly: true. If the volume allows read and write operations, check whether the RAM role that the Sandbox actually uses has write permissions. Also check whether the access control of the AgenticBucket allows the operations.

To troubleshoot further, retain the complete error message and the request ID.