When a Sandbox is running, you can call the append mount operation to add an AgenticBucket mount without recreating the Sandbox.
How it works
When you append a mount to a Sandbox in the running state, you can specify the AgenticBucket mount configuration directly, or reference an existing AgenticBucket volume by name.
This topic describes how to append an AgenticBucket mount to a running Sandbox. To specify the mount configuration when you create a Sandbox, see Mount AgenticBucket dynamically.
Prerequisites
-
The Sandbox is in the running state. If the Sandbox is paused, resume it first.
-
The API key that is used in the request belongs to the same team as the target Sandbox.
-
An AgenticBucket is created, and you know the full name of the BucketSpace that you want to access. 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.
-
The Sandbox is configured with a Resource Access Management (RAM) role, and the role has the access permissions on the target AgenticBucket and BucketSpace.
-
You have obtained the Object Storage Service (OSS) endpoint of the region in which the AgenticBucket resides. For access within the same region, the internal endpoint is recommended and requires no additional Virtual Private Cloud (VPC) configuration.
-
If you reference an existing volume, create the volume in the same team as described in Create an AgenticBucket Volume, and obtain the name of an available volume.
An append mount uses the current RAM role of the Sandbox. The append mount operation does not set or replace the role. If you reference an existing volume, the mountConfig.role of the volume does not replace the current role. For information about how to configure the role when you create a Sandbox, see Configure a RAM role.
For information about storage permission policies, see "Configure storage access permissions" in Create an AgenticBucket Volume. For information about the client requirements of the second-generation runtime, see Mount an AgenticBucket Volume.
The 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 in code or in the mount configuration. An append mount does not expand the authorization scope of the RAM role.
API operation and parameters
POST /sandboxes/{sandboxID}/fc-volume-mounts
The request headers must include X-API-Key and Content-Type: application/json. If the call succeeds, the API returns 204 No Content with an empty response body.
The request body supports both a direct mount configuration and references to existing volumes. The two methods can be combined in a single request:
|
Field |
Type |
Required |
Description |
|
|
Object |
Provide at least one of this field and |
Specifies the AgenticBucket mount configuration directly. For the fields, see the following table. |
|
|
Object array |
Provide at least one of this field and |
References existing volumes by name. |
|
|
String |
Required if you reference a volume. |
The name of a volume in the same team. Volume IDs are not supported. |
|
|
String |
Required if you reference a volume. |
The local mount directory in the Sandbox. |
The request must contain at least one valid mount point. The mount configuration in an append request is a JSON object, instead of the metadata parameter or a JSON string that is used when you create a Sandbox. Note the letter case: the metadata key that is used at creation is fc.sandbox.storage.agenticbucket, but the field in an append request is agenticBucket.
AgenticBucket mount parameters
The following fields are in inlineVolumeMounts.agenticBucket. If you specify the mount configuration directly, configure the fields as described in the following table:
|
Field |
Type |
Required |
Description |
|
|
Object array |
Yes |
The list of AgenticBucket mount points in this request. The list contains 1 to 5 mount points. The total number of existing and new AgenticBucket mount points cannot exceed 5. |
|
|
String |
Yes |
The full name of the AgenticBucket. |
|
|
String |
Yes |
The full name of the BucketSpace in the AgenticBucket. |
|
|
String |
No |
The path in the BucketSpace. If you do not specify this parameter, the default value |
|
|
String |
Yes |
The OSS endpoint, which must match the region and network environment of the AgenticBucket. |
|
|
String |
Yes |
The local mount directory in the Sandbox. For more information about the directory requirements, see Limits. |
|
|
Boolean |
No |
Specifies whether the mount is read-only. If you do not specify this parameter, the default value |
Local mount directory
mountDir and namedVolumeMounts[].path specify the local mount directory in the Sandbox. Configure them separately from bucketPath, which specifies the path in the BucketSpace. Use a subdirectory of /home, /mnt, /tmp, or /data. For more information about the directory limits, see Limits.
Install the SDK
The example uses httpx to call the append mount operation, and then uses the E2B SDK to connect to the existing Sandbox and verify read and write operations.
pip install e2b==2.31.0 httpx
Environment variables
|
Environment variable |
Purpose |
Source or value |
|
|
The API key that is used to call the Agent Sandbox API operations. |
Obtain the key in the Agent Sandbox console and use the API key of the destination team. |
|
|
The endpoint of the Agent Sandbox E2B API. |
|
|
|
The domain that the SDK uses to access the Sandbox. |
|
|
|
The ID of the Sandbox that receives the append mount request. |
Obtain the ID from the response that creates the Sandbox or from the Sandbox list. |
|
|
The full name of the AgenticBucket. |
Obtain the name from the AgenticBucket details in the OSS console. |
|
|
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. |
|
|
The internal OSS endpoint of the region in which the AgenticBucket resides. |
|
AGENTIC_BUCKET_NAME, BUCKET_SPACE_NAME, and OSS_ENDPOINT are specific to the storage type and are used only when you specify the mount configuration directly. If you reference an existing volume, you do not need to set these variables.
Append mount examples
Set the connection information in your local terminal and replace the placeholders with actual values:
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 SANDBOX_ID="<SANDBOX-ID>"
The following code runs on your local machine and accesses files in the Sandbox through the SDK. The example creates a separate test file with a random identifier, writes data to the file, reads the file for verification, deletes the file, and retains the Sandbox. Use a mount configuration that provides read and write permissions. If the mount allows only read operations, modify the verification code as described in Verify the mount.
Sandbox.connect() updates the timeout of the Sandbox. The example uses timeout=300 to set the timeout after the connection to 300 seconds. Adjust the value based on your task.
Select one of the following methods, or combine both methods in a single request:
-
Specify the mount configuration directly: provide the AgenticBucket mount parameters in
inlineVolumeMounts.agenticBucketof the request body. -
Reference an existing volume: reference a volume in the same team by name in
namedVolumeMountsof the request body.
Specify the mount configuration directly
The following example appends the root directory of the BucketSpace to /mnt/agentic-bucket and sets readOnly=False to verify read and write operations. Make sure that the RAM role also has the read and write permissions on the storage.
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"
Save the following code as append_agentic_bucket.py. Before you run the code, make sure that mount_dir is not used by an existing mount:
import os
from uuid import uuid4
import httpx
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
def verify_read_write(sandbox: Sandbox, mount_dir: str) -> None:
marker_path = f"{mount_dir}/mount-check-{uuid4().hex}.txt"
expected = f"append mount check {uuid4().hex}\n"
sandbox.files.write(marker_path, expected)
try:
content = sandbox.files.read(marker_path)
if content != expected:
raise RuntimeError(f"File content verification failed: {marker_path}")
finally:
sandbox.files.remove(marker_path)
print(f"Read/write verification passed. Test file deleted: {mount_dir}")
api_key = require_env("E2B_API_KEY")
api_url = require_env("E2B_API_URL").rstrip("/")
domain = require_env("E2B_DOMAIN")
sandbox_id = require_env("SANDBOX_ID")
mount_dir = "/mnt/agentic-bucket"
payload = {
"inlineVolumeMounts": {
"agenticBucket": {
"mountPoints": [{
"agenticBucket": require_env("AGENTIC_BUCKET_NAME"),
"bucketName": require_env("BUCKET_SPACE_NAME"),
"bucketPath": "/",
"endpoint": require_env("OSS_ENDPOINT"),
"mountDir": mount_dir,
"readOnly": False,
}],
},
},
}
response = httpx.post(
f"{api_url}/sandboxes/{sandbox_id}/fc-volume-mounts",
headers={"X-API-Key": api_key},
json=payload,
timeout=120.0,
)
if response.status_code != 204:
raise RuntimeError(f"Append mount failed: HTTP {response.status_code}, {response.text}")
sandbox = Sandbox.connect(
sandbox_id,
timeout=300,
api_key=api_key,
api_url=api_url,
domain=domain,
)
verify_read_write(sandbox, mount_dir)
Run the example:
python append_agentic_bucket.py
Reference an existing volume
If an AgenticBucket volume already exists, replace the payload definition in the preceding script with the following content before the first run, and keep the rest of the code unchanged. Replace name with the name of a volume in the same team. The volume must allow read and write operations for the verification to pass.
payload = {
"namedVolumeMounts": [{
"name": "agentic-bucket-workspace",
"path": mount_dir,
}],
}
Run one example script at a time. You cannot append to the same mount directory twice. If the mount succeeds but the verification fails, run only the connection and verification code again. Do not submit the append request again.
If you combine a direct configuration and a volume reference, put both configurations in the same request body and specify a different local mount directory for each mount point. For the complete procedure and the multi-volume example that references volumes by name, see Append a volume mount.
Verify the mount
The example connects to the Sandbox and verifies file read and write operations only after the API returns 204. The output "Read/write verification passed. Test file deleted" indicates that the write operation, the content comparison, and the deletion are complete.
A read-only mount verifies only read operations. If you specify the mount configuration directly, set readOnly to True. If you reference a volume, use an existing read-only volume. Before the first run, replace verify_read_write(sandbox, mount_dir) at the end of the example with the following code. Then replace <EXISTING-FILE> with the relative path of a file that already exists in the mount directory. A newly created BucketSpace may be empty, so the read verification requires an existing file.
file_path = f"{mount_dir}/<EXISTING-FILE>"
content = sandbox.files.read(file_path, format="bytes")
print(f"Read succeeded: {file_path}, {len(content)} bytes")
For a mount that references a volume, you can also query the mount through the SDK after the connection succeeds:
print(sandbox.get_info().volume_mounts)
In the SDK, the volume_mounts field corresponds to the GET /sandboxes/{sandboxID} response, where the field is named volumeMounts. Mounts that use a direct configuration do not appear in this field and must be verified through file access. The existence of a directory does not mean that data access works.
Behavior notes
Releasing a Sandbox does not delete the data in the BucketSpace. Clean up test files and task data separately 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 different storage types.
-
The operation only adds mounts. It does not unmount or replace existing mounts. To remove an existing mount, release and recreate the Sandbox. Omitting an existing mount in a request does not delete it, and submitting the same mount again returns
400. -
The total number of existing and new AgenticBucket mount points cannot exceed 5. Do not count only the mount points in this request.
-
The AgenticBucket, BucketSpace, OSS endpoint, and Sandbox must use matching regions and network environments.
-
Do not concurrently modify the mounts of the same Sandbox.
FAQ
Why is the request rejected by the API key policy?
If the error message is request is not allowed by API key policy, check whether the API key policy allows the mount method and the storage type of this request. For more information, see Manage API keys. This type of rejection occurs at the API authorization stage. Adjusting the RAM role of the storage does not resolve it.
Why does the system report that the volume cannot be found when I mount by name?
Check the volume name in the request, the team that owns the API key, and the region of the API endpoint. Make sure that you use the name of a volume in the same team instead of a volume ID. For more information, see Append a volume mount.
Why does the system report that the volume is unavailable when I mount by name?
Query the status and the status reason of the volume by using GetVolume. Mount the volume only after you confirm that it is available. If a failure reason exists, resolve it first. For more information, see Append a volume mount.
Why does the append mount report that the Sandbox is not running?
If the error message is sandbox must be running, confirm that the target Sandbox is in the running state. If the Sandbox is paused, resume it first. If the Sandbox is released, recreate it.
Why does the append mount report a missing RAM role?
If the error message contains FC Function execution Role is required, the current Sandbox is not configured with the required RAM role. The append mount operation uses the current role and does not set the role for the Sandbox from the mountConfig.role of the new volume.
Prepare a role that has the access permissions on the target storage, and configure the role when you recreate the Sandbox. For more information, see Configure a RAM role.
Why does the append mount report a duplicate mount directory?
If the error message contains duplicate mount path or duplicate mount dir, check whether the local mount directories in this request are duplicated, and whether a directory is already used by another mount in the Sandbox. Different storage types cannot share the same local mount directory.
Do not submit existing mounts again. Use an unused directory for the new mount. The append mount operation cannot overwrite or replace existing mounts.
Why is the mount limit exceeded when I append only one mount point?
The number of mounts is calculated from the existing mounts of the Sandbox and the new mounts in this request. Both mounts that specify the configuration directly and mounts that reference volumes are counted. Do not check only the number of mounts in this request.
Check the number of mounts for the corresponding storage type as described in Limits of this topic. If the limit is reached, mount the new storage in another Sandbox. Changing the local mount directory does not reduce the number of existing mounts.
If the issue persists, or if the API reports that the service is temporarily unavailable, retain the complete error message and the request ID, and contact technical support.