After a Sandbox is created, append existing volumes by name without recreating the Sandbox.
How it works
When you append a mount, you need to provide only the volume name and the mount directory in the Sandbox. The storage configuration is read from the volume.
This topic describes how to append existing volumes by using namedVolumeMounts. To provide the storage configuration directly in a request, see Append an OSS mount, Append an AgenticFS mount, Append an AgenticBucket mount, or Append a JuiceFS mount.
Prerequisites
-
The Sandbox is in the
runningstate. If the Sandbox is paused, resume it first. -
You have prepared an Agent Sandbox API key. The API key, the Sandbox, and the target volume belong to the same team. For more information, see Create an API Key.
-
The target volume is created and is in the available state.
-
The Sandbox is configured with the Resource Access Management (RAM) role, network configuration, and storage client that the storage type requires.
The following table describes the Sandbox configuration requirements of each storage type. For information about the client, storage authorization, and connectivity requirements, see the corresponding mount topic.
|
Volume type |
RAM role |
Virtual Private Cloud (VPC) configuration |
References |
|
OSS Volume |
Required |
Not required |
|
|
AgenticFS Volume |
Required |
Required |
|
|
AgenticBucket Volume |
Required |
Not required |
|
|
JuiceFS Volume |
Not required |
Not required |
An append mount uses the existing RAM role and VPC configuration of the Sandbox. The mountConfig.role and mountConfig.vpcConfig of a volume do not change these configurations. For a storage type that requires a RAM role, the existing role of the Sandbox must have the permissions to access the new storage. For information about how to configure the role for a single volume, multiple volumes, or a mount that you append after the Sandbox is created, see Configure a RAM role.
To access storage that requires a VPC, the Sandbox must be configured with vpcId, securityGroupId, and vSwitchIds (which must contain at least one vSwitch ID). The Sandbox must also be able to access the target storage. If the required role or VPC configuration is missing, recreate the Sandbox and then mount the storage.
Procedure
Step 1: Install the SDK
The example uses httpx to call the append mount operation. After the call succeeds, the example uses the E2B SDK to connect to the existing Sandbox and verify file read and write operations.
pip install e2b==2.31.0 httpx
Step 2: Append volume mounts
API operation and parameters
POST /sandboxes/{sandboxID}/fc-volume-mounts
The request uses X-API-Key for authentication, and Content-Type is set to application/json. To append existing volumes by using namedVolumeMounts, configure the following request parameters:
|
Parameter |
Type |
Required |
Description |
|
|
Object array |
Yes |
The volumes to append in this request. The array must contain at least one item. |
|
|
String |
Yes |
The name of a volume in the current team. Volume IDs are not supported. |
|
|
String |
Yes |
The local mount directory in the Sandbox, instead of the remote directory in the storage service. |
If the call succeeds, the API returns 204 No Content with an empty response body.
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 current team. |
|
|
The endpoint of the Agent Sandbox E2B API. |
Set the value to |
|
|
The domain that the SDK uses to access the Sandbox. |
Set the value to |
|
|
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. |
Append one volume
Set the connection information in your local terminal and replace the placeholders with actual values. For the value of each variable, see Environment variables of 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 SANDBOX_ID="<SANDBOX-ID>"
The following code runs on your local machine and accesses files in the Sandbox through the SDK. For each new mount, the example creates a separate test file with a random identifier, writes data to the file, and reads the file for verification. The example then deletes the test file and retains the Sandbox. Use a volume that allows read and write operations. For information about how to verify a volume that allows only read operations, see Step 3: Verify the mount of this topic.
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.
The following example appends the existing oss-workspace volume to /mnt/oss. Replace the volume name and the mount directory with actual values, make sure that the mount directory is not in use, and save the code as append_volume.py:
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")
mounts = [
{"name": "oss-workspace", "path": "/mnt/oss"},
]
payload = {"namedVolumeMounts": mounts}
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,
)
for mount in mounts:
verify_read_write(sandbox, mount["path"])
Run the example:
python append_volume.py
Append multiple volumes
Before the first run, replace the mounts definition in the preceding script with the following content to append two existing volumes in a single request. Replace the volume names with actual values, and make sure that both volumes allow read and write operations. The script verifies each mount directory one by one.
mounts = [
{"name": "project-data", "path": "/mnt/project"},
{"name": "project-results", "path": "/mnt/results"},
]
A single request can reference volumes of different storage types, but the Sandbox must meet the access requirements of all of them. The RAM roles configured in the volumes are not merged and do not replace the existing role of the Sandbox.
The request lists only the mounts that you want to add. Existing mounts are retained, and submitting the same mount again returns 400. If the mount succeeds but the verification fails, run only the connection and verification code again. Do not submit the append request again.
Step 3: Verify the mount
The example connects to the Sandbox and verifies file read and write operations for each new mount only after the API returns 204. The output "Read/write verification passed. Test file deleted" for a mount directory indicates that the write operation, the content comparison, and the deletion are complete.
For a volume that allows only read operations, perform read verification only. Before the first run, replace the verification loop at the end of the script with the following code. This example uses /mnt/oss. Replace <EXISTING-FILE> with the relative path of a file that already exists in the mount directory:
file_path = "/mnt/oss/<EXISTING-FILE>"
content = sandbox.files.read(file_path, format="bytes")
print(f"Read succeeded: {file_path}, {len(content)} bytes")
If the volumes in a Sandbox have different read and write permissions, read a known file for each read-only mount, and call verify_read_write(sandbox, mount_dir) for each writable mount. Do not perform write verification on read-only mounts.
After the connection succeeds, the SDK can also return the volume names and mount directories:
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. The existence of a mount record and a directory does not mean that data access works. You must still verify file read or write access.
Behavior notes
Releasing a Sandbox does not delete the data in the underlying storage. Clean up test files and task data separately in the corresponding storage service or through the mount directory.
Limits
-
For security reasons, OSS mounts do not support Key Management Service (KMS) server-side encryption (SSE-KMS).
-
You cannot delete, replace, or unmount an existing mount. To remove a mount, release and recreate the Sandbox.
-
The directories that you add in this request must be different from each other, and cannot duplicate or overlap with existing mount directories.
-
Use a normalized absolute Unix path. The path cannot be
/, cannot contain leading or trailing spaces,.or..path segments, and cannot contain a hidden directory such as.cache. Prefer a subdirectory of/mnt,/data,/home, or/tmp. System directories such as/bin,/opt,/var, and/devare not supported, nor are their subdirectories. -
In the same Sandbox, OSS, AgenticFS, AgenticBucket, and JuiceFS each support up to five mount points. The count includes mounts created with the Sandbox and appended later, and mounts that specify the storage configuration directly.
-
The User ID (UID) or Group ID (GID) of a new AgenticFS mount cannot conflict with the existing configuration of the current Sandbox. Existing and new JuiceFS mounts must use the same service address.
-
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 Create an API Key. This type of rejection occurs at the API authorization stage. Adjusting the RAM role of the storage does not resolve it.
Why does the append mount report a UID or GID conflict for AgenticFS?
Check the UID and GID configuration of the new volume, and make sure that the configuration is compatible with the existing configuration of the current Sandbox. For more information, see Append an AgenticFS mount.
Why does the append mount report a JuiceFS service address conflict?
Check the baseURL of the new volume, and make sure that it uses the same service address as the existing JuiceFS mounts of the current Sandbox. For more information, see Append a JuiceFS 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 system report 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. To mount by name, use a volume that exists in the same team. Volume IDs are not supported.
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.
Why does the append mount report an incomplete VPC configuration for the Sandbox?
If the error message contains FC Function complete VPC configuration is required, the missing configuration belongs to the current Sandbox. The mountConfig.vpcConfig in the append request or in the new volume does not supply the missing configuration.
When you recreate the Sandbox, configure the complete vpcId, securityGroupId, and a non-empty vSwitchIds. When you create the Sandbox, provide these values by using metadata, or use the VPC configuration that the referenced volume stores.
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. Also verify that no 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.