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), set buildConfig.installStorageClients
when you create the template. Template Build then automatically installs the ossfs2 client that the mount requires. For more information, see Step 1: Pre-install storage clients when you create a template in this topic.
Procedure
Step 1: Pre-install storage clients when you create a template
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.
When you create a custom template with the second-generation runtime (MicroVM), you can use buildConfig.installStorageClients to automatically install the persistent storage clients. This parameter supports only the second-generation runtime. Set generation: 2 in runtimeConfig.sandboxConfig.
For a request body example and the complete limits, see the "Install storage clients" section in Build and manage custom templates with code.
After you enable this parameter, Template Build pre-installs ossfs2 and its runtime dependencies in the template image. This parameter does not create storage resources, perform mounts, or configure the network or access credentials. When you create a Sandbox, you must still configure the mount parameters, the network, and the access credentials as described in this topic. Verify that the mount is available by performing actual read and write operations.
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 |
|
|
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. |
|
|
The endpoint of the E2B API. |
Set the value to |
|
|
The service domain that the SDK uses. |
Set the value to |
|
|
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. |
|
|
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_mountsuses 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.
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 the storage client is installed as described in Step 1: Pre-install storage clients when you create a template 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.