Mount an AgenticFS Volume
When you create a Sandbox, use volume_mounts to mount an existing AgenticFS Volume to a specified directory.
How it works
After the volume is mounted, the Sandbox can access AgenticFS through file paths, and the data is not deleted when the Sandbox is released.
To append a mount to a running Sandbox, see Append a volume mount.
Prerequisites
-
You have created an AgenticFS Volume for the destination 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 virtual private cloud (VPC), a vSwitch, and a security group that can reach the AgenticFS Access Point.
-
You have prepared a Resource Access Management (RAM) role. The role has the AgenticFS mount and read and write permissions, and its trust policy 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.
Important: Before you create a Sandbox, make sure that the corresponding AgenticFS Access Point is in theactivestate. Otherwise, thecreateSandboxcall may time out or fail. To check the status, log on to the AgenticFS console, find the corresponding file system, and then go to the file system details page. Click Mount and Use to view the Access Point status.
The VPC configuration that you use to create the Sandbox must contain vpcId, securityGroupId, and a non-empty vSwitchIds, and must be able to access the destination storage. The VPC configuration in a template cannot replace this mount configuration.
When 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 AgenticFS 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), 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 the aliyun-alinas-utils (mount.alinas) client and the nfs-common package that this topic requires, together with their dependencies, into the template image. This parameter does not create storage resources, perform mounts, or configure the network and 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. Then 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 for demonstration. volume_mounts requires E2B Python SDK 2.31.0.
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 how to specify the 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 in Prerequisites in this topic. Obtain the value in the Agent Sandbox console. |
|
|
The name of the AgenticFS Volume to mount. |
Use the name that you set in Create an AgenticFS 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 and example values 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="code-interpreter-v1"
export AGENTICFS_VOLUME_NAME="agent-workspace"
The 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/agenticfs.
The following example reuses the mountConfig.role and mountConfig.vpcConfig of the volume to mount the AgenticFS Volume to /mnt/agenticfs. Make sure that the volume stores a RAM role and a complete VPC configuration. For the role selection rules, see Configure a 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. The example 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 02_mount_agenticfs_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/agenticfs"
marker_path = f"{mount_dir}/hello-agenticfs-{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("AGENTICFS_VOLUME_NAME")},
)
info = sandbox.get_info()
print(f"volume_mounts={info.volume_mounts}")
sandbox.files.write(marker_path, "hello agenticfs\n")
marker_written = True
content = sandbox.files.read(marker_path)
if content != "hello agenticfs\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("AgenticFS Volume read/write verification passed")
Run the example:
python 02_mount_agenticfs_volume.py
If the output shows AgenticFS Volume read/write verification passed, 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 a Sandbox is resumed after it is paused, the volume mount is restored.
-
Releasing a Sandbox does not delete the data in AgenticFS. The test file is deleted by the example. The retention and cleanup of other data must be handled separately.
-
This topic reuses the
mountConfig.vpcConfigof the volume. To override the configuration, provide a complete VPC configuration in thefc.sandbox.network.vpcfield of the metadata when you create the Sandbox. If you configure both locations, the metadata configuration takes precedence.
Limits
-
A single Sandbox supports a maximum of five AgenticFS mount points. The count includes mounts created with the Sandbox, mounts appended later, and 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 such a directory. The mount directory also cannot contain a hidden directory, such as.cache, whose name starts with.. -
To access the mounted content through a hidden directory, mount the volume to a directory that meets the requirements. Then use
ln -sto create a symbolic link that points to the mount directory. -
Mount directories cannot be duplicated in the same Sandbox.
-
The mount directory can contain a maximum of 128 characters.
-
When you create a Sandbox, the
userIDandgroupIDconfigurations of multiple AgenticFS Volumes must be identical. When you append a mount, the user ID (UID) and group ID (GID) of the new mount must not conflict with the existing configuration of the 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 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 AgenticFS mount requires Function role, the system did not obtain the RAM role required for the mount.
The example in this topic obtains the role from the mountConfig.role of the volume. If the metadata of the creation request explicitly sets fc.sandbox.auth.role, that value takes precedence. Check the role configuration actually used, add a valid role ARN (Alibaba Cloud Resource Name), and then submit the creation request again. For information about how to configure the role, see Configure a RAM role.
The VPC is configured, but why does the system report an incomplete configuration?
If the error message contains mount requires complete VPC config, the VPC configuration used for this creation is missing required fields.
If you did not specify a VPC in the metadata, check the mountConfig.vpcConfig of the volume. If you specified a VPC, check fc.sandbox.network.vpc. The configuration actually used must contain vpcId, securityGroupId, and a non-empty vSwitchIds. The metadata configuration takes precedence. The system does not use the fields of the volume to complete an incomplete metadata configuration.
Sandbox creation times out or the mount fails
If the error message does not indicate a specific parameter issue, check the actual mount conditions in the following order:
-
Make sure that the Access Point is in the
activestate, and that the address and the remote directory match the values you set when creating the volume. -
Check the routes of the VPC used by the Sandbox, the security group, and the connectivity between the Sandbox and the Access Point.
-
Check the RAM role actually used. Make sure that the trust policy allows the Function Compute service to assume the role and that the role has the access permissions required by the destination storage.
-
If you use a custom template of the second-generation runtime, verify that the AgenticFS client is installed. For the installation steps, see Step 1: Pre-install storage clients when you create a template in this topic.
The volume is mounted, but file read and write operations fail
First, make sure that your application accesses the local mount directory that you specified. Then, based on the error returned for the file operation, check the directory permissions, the UID, and the GID. Verify whether the RAM role actually used has the read and write permissions. The access status of the Access Point must also be normal.
To troubleshoot further, retain the complete error message and the request ID.