All Products
Search
Document Center

Agent Sandbox:Mount AgenticBucket dynamically

Last Updated:Oct 13, 2026

When you create a Sandbox, mount a BucketSpace or its subdirectory under an AgenticBucket to a local mount directory in the Sandbox by using metadata. You do not need to create a volume in advance.

How it works

When you create a Sandbox, specify the mount in metadata. The system then mounts the BucketSpace or its subdirectory under an AgenticBucket to the Sandbox. After the mount is complete, your application accesses data through the local mount directory.

To add a mount to a running Sandbox, see Append an AgenticBucket mount.

Prerequisites

For more information about AgenticBucket and how its resources are managed, see OSS Agentic Bucket overview.

  • You have created an AgenticBucket and obtained its full name.

  • You have determined the full name of the BucketSpace that you want to use. You do not need to create the BucketSpace in advance. If the BucketSpace does not exist on the first mount, the system creates it automatically.

  • You have obtained the Object Storage Service (OSS) endpoint of the region in which the AgenticBucket resides. For access within the same region, use the internal endpoint. Example: https://oss-<REGION>-internal.aliyuncs.com. You do not need to configure a Virtual Private Cloud (VPC).

  • You have prepared an Agent Sandbox API key and an available template.

  • You have prepared a Resource Access Management (RAM) role whose trust policy allows the Function Compute service to assume the role. The role has the access permissions required by the target storage. For information about how to configure the role, see Configure a RAM role. For information about storage permission policies, see Create an AgenticBucket Volume.

Image requirements for the second-generation runtime

If you use a custom template of the second-generation runtime (MicroVM), you must pre-install the storage client before you build the template. For information about how to install the client, build the image, and verify the result, see Mount an AgenticBucket Volume.

Install the SDK

Create and activate a Python virtual environment, and then install the E2B SDK:

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

Mount configuration

When you create a Sandbox, provide the following configuration in metadata:

Metadata key

Value format

Description

fc.sandbox.storage.agenticbucket

JSON string

The AgenticBucket mount configuration. For information about the fields, see the following table.

fc.sandbox.auth.role

String

The Alibaba Cloud Resource Name (ARN) of the valid RAM role used to access the target storage. This parameter is required and cannot be an empty string.

fc.sandbox.storage.agenticbucket uses the following JSON structure. Serialize the structure to a string before you submit the request. You cannot pass a Python dictionary or a JavaScript object directly:

{
  "mountPoints": [
    {
      "agenticBucket": "<AGENTIC-BUCKET-FULL-NAME>",
      "bucketName": "<BUCKET-SPACE-FULL-NAME>",
      "mountDir": "/mnt/agentic-bucket",
      "bucketPath": "/",
      "endpoint": "https://oss-<REGION>-internal.aliyuncs.com",
      "readOnly": false
    }
  ]
}

Field

Type

Required

Description

mountPoints

Array of objects

Yes

The list of AgenticBucket mount points.

mountPoints[].agenticBucket

String

Yes

The full name of the AgenticBucket.

mountPoints[].bucketName

String

Yes

The full name of the BucketSpace in the AgenticBucket.

mountPoints[].mountDir

String

Yes

The local mount directory in the Sandbox, which must be an absolute path. Example: /mnt/agentic-bucket.

mountPoints[].bucketPath

String

No

The path in the BucketSpace. If you do not specify this parameter, the default value / is used.

mountPoints[].endpoint

String

Yes

The OSS endpoint, which must match the region and network environment of the AgenticBucket.

mountPoints[].readOnly

Boolean

No

Specifies whether the mount is read-only. If you do not specify this parameter, the default value false is used.

bucketName uses the full name of the BucketSpace, and bucketPath selects a path under it. To grant read-only access, set readOnly to true.

Agent Sandbox obtains Security Token Service (STS) temporary credentials through the RAM role. You do not need to disable BlockPublicAccess for the AgenticBucket, and you do not need to provide long-term AccessKey pairs (AK/SK) in the mount configuration. The mount configuration does not expand the authorization scope of the RAM role.

Local mount directory

mountDir specifies the local mount directory in the Sandbox. The remote directory is specified separately in the storage configuration. Use a subdirectory of /home, /mnt, /tmp, or /data to avoid overwriting the existing content of the template. For information about the directory limits, see Limits.

Environment variables

Environment variable

Purpose

Source or value

E2B_API_KEY

The API key used to call the Agent Sandbox API operations.

Create the key in the Agent Sandbox console and use the API key of the target team.

E2B_API_URL

The endpoint of the Agent Sandbox E2B API.

https://api.<REGION>.sandbox.aliyuncs.com. Replace <REGION> with the target region.

E2B_DOMAIN

The domain that the SDK uses to access the Sandbox.

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

E2B_TEMPLATE

The template ID or alias used to create the Sandbox.

In the Agent Sandbox console, select a template that meets the client requirements described in this topic.

AGENTIC_BUCKET_NAME

The full name of the AgenticBucket.

Obtain the name on the AgenticBucket details page in the OSS console.

BUCKET_SPACE_NAME

The full name of the BucketSpace that you want to mount.

Use the full name of an existing BucketSpace, or specify the name of the BucketSpace that you want to create on the first mount.

OSS_ENDPOINT

The OSS endpoint used to access the AgenticBucket.

Obtain the endpoint in the OSS console. The endpoint must match the region and network of the target storage.

SANDBOX_ROLE_ARN

The ARN of the RAM role used to access the target storage.

Configure a RAM role. Obtain the ARN from the role details page in the RAM console.

Mount and verify

Set the environment variables and replace the placeholders in the examples. The API endpoint, the template, and the storage must use matching regions and network configurations:

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_NAME="<AGENTIC-BUCKET-FULL-NAME>"
export BUCKET_SPACE_NAME="<BUCKET-SPACE-FULL-NAME>"
export OSS_ENDPOINT="https://oss-<REGION>-internal.aliyuncs.com"
export SANDBOX_ROLE_ARN="acs:ram::<ACCOUNT-ID>:role/<ROLE-NAME>"

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

Save the following code as 11_sandbox_agentic_bucket.py:

import json
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"
agentic_bucket_config = {
    "mountPoints": [
        {
            "agenticBucket": require_env("AGENTIC_BUCKET_NAME"),
            "bucketName": require_env("BUCKET_SPACE_NAME"),
            "mountDir": mount_dir,
            "bucketPath": "/",
            "endpoint": require_env("OSS_ENDPOINT"),
            "readOnly": False,
        }
    ]
}

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"),
        metadata={
            "fc.sandbox.storage.agenticbucket": json.dumps(agentic_bucket_config),
            "fc.sandbox.auth.role": require_env("SANDBOX_ROLE_ARN"),
        },
    )

    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"Unexpected file content: {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 dynamic mount read/write verification succeeded")

Run the example:

python 11_sandbox_agentic_bucket.py

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

Behavior notes

Releasing a Sandbox does not delete the underlying storage data. The example deletes the test file on its own. To retain or clean up other data, handle it in the storage service or through the local mount directory.

Limits

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

  • The local mount directory cannot be a system directory or a subdirectory of one, such as /bin, /opt, /var, or /dev. It also cannot contain a hidden directory such as .cache. To access data through a hidden directory, mount the storage to a directory that meets the requirements and then create a symbolic link that points to the local mount directory.

  • Local mount directories cannot be duplicated in the same Sandbox. This limit applies across storage types.

  • A Sandbox supports up to five AgenticBucket mount points. The mount point limit includes the mounts specified at creation and the mounts appended later. Both directly configured mounts and mounts that reference volumes are counted.

FAQ

Why does Sandbox creation report a missing RAM role?

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

Following the examples in this topic, provide a valid role ARN in the metadata by using fc.sandbox.auth.role, and then submit the creation request again. For information about how to configure the role, see Configure a RAM role.

What do I do if the mount fails when a Sandbox is created?

Check the full name of the AgenticBucket, the full name of the BucketSpace, and the endpoint against the error message. If the message indicates that access to the storage is denied, check the trust policy and the storage access permissions of the role specified by fc.sandbox.auth.role. If you use a custom template of the second-generation runtime, verify that the storage client is installed, as described in the image requirements in this topic.

Why can I read the local mount directory but not write to it?

Check whether this mount is configured with readOnly: true. A read-only mount does not allow write operations.

If the mount is read and write, check whether the RAM role has the write permissions, and whether the access control of the AgenticBucket allows the operation.

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