When you create a Sandbox, use metadata to mount an AgenticSpace Access Point or its subdirectory to a local directory in the Sandbox, without creating a volume in advance.
How it works
When you create a Sandbox, use metadata to mount an AgenticSpace Access Point or its subdirectory to the Sandbox, without creating a volume in advance. 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 AgenticFS mount.
Prerequisites
For more information about AgenticFS, see AgenticFS. The related resources are created and managed in the NAS console.
-
You have created an AgenticFS file system, an AgenticSpace, and an AgenticSpace Access Point for which Resource Access Management (RAM) authentication is enabled. The Access Point is in the
activestate. -
You have obtained the address of the Access Point, for example,
ap-<ACCESS-POINT-ID>.<FILE-SYSTEM-ID>-<SUFFIX>.<REGION>.nas.aliyuncs.com:/. -
You have prepared a Virtual Private Cloud (VPC), a vSwitch, and a security group, all of which can reach the Access Point over the network.
-
You have prepared an Agent Sandbox API key and an available template.
-
You have prepared a RAM role whose trust policy allows the Function Compute service to assume the role, and 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 AgenticFS 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 AgenticFS 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, specify the following items in metadata:
|
Metadata key |
Value format |
Description |
|
|
JSON string |
The AgenticFS mount configuration. For information about the fields, see the following table. |
|
|
JSON string |
The complete VPC configuration, which includes |
|
|
String |
The Alibaba Cloud Resource Name (ARN) of the valid RAM role that is used to access the target storage. This parameter is required and cannot be an empty string. |
To specify the mount configuration directly when you create a Sandbox, you must also provide the complete VPC configuration as a JSON string in fc.sandbox.network.vpc. The VPC configuration of the template or of a volume in the same request cannot replace this metadata.
The following JSON structure shows the value of fc.sandbox.storage.agenticfs. Before you submit the request, serialize the structure to a string. You cannot pass a Python dictionary or a JavaScript object:
{
"userID": 1000,
"groupID": 1000,
"mountPoints": [
{
"serverAddr": "ap-<ACCESS-POINT-ID>.<FILE-SYSTEM-ID>-<SUFFIX>.<REGION>.nas.aliyuncs.com:/project-a",
"mountDir": "/mnt/agenticfs"
}
]
}
|
Field |
Type |
Required |
Description |
|
|
Integer |
No |
The user ID (UID) that is used for the mount. Valid values: |
|
|
Integer |
No |
The user group ID (GID) that is used for the mount. Valid values: |
|
|
Array of objects |
Yes |
The list of AgenticFS mount points. At least one mount point is required. |
|
|
String |
Yes |
The address of the Access Point, which can be up to 128 characters in length. Standard NAS mount addresses and URLs that include a protocol prefix are not supported. A remote subdirectory under the Access Point can be specified after |
|
|
String |
Yes |
The local mount directory in the Sandbox, which can be up to 128 characters in length. The directory must be a normalized absolute Unix path, for example, |
The metadata key must be fc.sandbox.storage.agenticfs in lowercase. Field names in the configuration are also case-sensitive. You must use userID, groupID, serverAddr, and mountDir. The platform automatically enables TLS. Do not specify enableTLS. The configuration is parsed in strict JSON mode. Undeclared fields such as readOnly cause the request to fail.
Mount a subdirectory under an Access Point
To mount only a subdirectory under the Access Point, specify the remote directory after :/ in serverAddr. Example: ap-<ACCESS-POINT-ID>.<FILE-SYSTEM-ID>-<SUFFIX>.<REGION>.nas.aliyuncs.com:/project-a. If the subdirectory does not exist, the system automatically creates it on the first mount.
The remote directory must be a normalized absolute path. It cannot contain whitespace characters, control characters, repeated separators, ., or ... Except for the root directory /, the path cannot end with /.
The permission boundary of AgenticFS is determined by the Access Point. A remote subdirectory under the Access Point determines only the mount location. It does not further narrow the access scope of the Security Token Service (STS) temporary credentials. To isolate data, use separate Access Points.
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 |
|
|
The API key that is 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. |
|
|
The endpoint of the Agent Sandbox E2B API. |
|
|
|
The domain that the SDK uses to access the Sandbox. |
|
|
|
The template ID or alias that is used to create the Sandbox. |
In the Agent Sandbox console, select a template that meets the client requirements described in this topic. |
|
|
The address of the Access Point and the remote directory. |
Obtain the address of the Access Point in the NAS console and specify a directory under the Access Point after |
|
|
The UID that is used for the mount. |
Set this value based on the user that accesses data in the Sandbox. The example uses |
|
|
The GID that is used for the mount. |
Set this value based on the user group that accesses data in the Sandbox. The example uses |
|
|
The VPC in which the Sandbox resides. |
Obtain the value in the VPC console. The VPC must be connected to the network of the target storage. |
|
|
The security group that the Sandbox uses. |
Obtain the value in the ECS console. The security group must belong to the selected VPC and allow access to the target storage. |
|
|
The vSwitch that the Sandbox uses. |
Obtain the value in the VPC console. The vSwitch must belong to the selected VPC. |
|
|
The ARN of the RAM role that is used to access the target storage. |
Obtain the value from the role details page in the RAM console. For information about how to create the role, see Configure a RAM role. |
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 AGENTICFS_SERVER_ADDR="ap-<ACCESS-POINT-ID>.<FILE-SYSTEM-ID>-<SUFFIX>.<REGION>.nas.aliyuncs.com:/"
export AGENTICFS_USER_ID="1000"
export AGENTICFS_GROUP_ID="1000"
export SANDBOX_VPC_ID="vpc-xxxxxxxx"
export SANDBOX_SECURITY_GROUP_ID="sg-xxxxxxxx"
export SANDBOX_VSWITCH_ID="vsw-xxxxxxxx"
export SANDBOX_ROLE_ARN="acs:ram::<ACCOUNT-ID>:role/<ROLE-NAME>"
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 that is created in the process. Use a mount configuration that provides read and write permissions.
Save the following code as 12_sandbox_agenticfs.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/agenticfs"
marker_path = f"{mount_dir}/hello-agenticfs-{uuid4().hex}.txt"
agenticfs_config = {
"userID": int(require_env("AGENTICFS_USER_ID")),
"groupID": int(require_env("AGENTICFS_GROUP_ID")),
"mountPoints": [
{
"serverAddr": require_env("AGENTICFS_SERVER_ADDR"),
"mountDir": mount_dir,
}
],
}
vpc_config = {
"vpcId": require_env("SANDBOX_VPC_ID"),
"securityGroupId": require_env("SANDBOX_SECURITY_GROUP_ID"),
"vSwitchIds": [require_env("SANDBOX_VSWITCH_ID")],
}
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.agenticfs": json.dumps(agenticfs_config),
"fc.sandbox.network.vpc": json.dumps(vpc_config),
"fc.sandbox.auth.role": require_env("SANDBOX_ROLE_ARN"),
},
)
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"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("AgenticFS dynamic mount read/write verification succeeded")
Run the example:
python 12_sandbox_agenticfs.py
If the output is AgenticFS 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 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, and 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 mount directory. -
Local mount directories cannot be duplicated in the same Sandbox, including mount directories of other storage types.
-
A Sandbox supports up to five AgenticFS mount points, counted cumulatively for the mounts specified at creation and the mounts appended later. Both directly configured mounts and mounts that reference volumes are counted.
-
Multiple AgenticFS mount points in the same Sandbox share one pair of
userIDandgroupIDvalues. All mount points within a single mount configuration share the values. The UID or GID that you specify for an append mount cannot conflict with the existing configurations of the Sandbox.
FAQ
Why does the system report an incomplete configuration after I configure a VPC?
If the error message contains mount requires complete VPC config, the VPC configuration used in this creation request is missing required fields.
In the metadata of this creation request, pass a JSON string by using fc.sandbox.network.vpc. The string must contain vpcId, securityGroupId, and a non-empty vSwitchIds. If you specify the mount configuration directly, you must also specify this metadata. The VPC configuration of the template or of a volume in the same request cannot replace it.
Why does Sandbox creation report a missing RAM role?
If the error message contains AgenticFS mount requires Function role, the creation request did not obtain the RAM role that is required for the mount.
As shown in the examples in this topic, provide a valid role ARN by using fc.sandbox.auth.role in the metadata of the creation request, and then submit the creation request again. For information about how to configure the role, see Configure a RAM role.
Why does metadata report an unknown field?
If the error message contains json: unknown field, check the configuration against the field that is specified in the message. AgenticFS accepts only the fields declared in the parameter tables of this topic, and field names are case-sensitive.
For example, use userID instead of userId, and use serverAddr instead of serveraddr. Remove unsupported fields such as enableTLS and readOnly. The platform enables TLS. You do not need to configure TLS in the mount configuration.
What do I do if 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:
-
Confirm that the Access Point is in the
activestate, and that the address and the remote directory are correct. -
Check the routes and the security group of the VPC that the Sandbox uses, and the connectivity to the Access Point.
-
Check the RAM role that is actually used. Confirm that the trust policy allows the Function Compute service to assume the role and that the role has the access permissions required by the target storage.
-
If you use a custom template of the second-generation runtime, verify the AgenticFS client as described in the image requirements in this topic.
To troubleshoot further, retain the complete error message and the request ID.