When you create a Sandbox, use volume_mounts to mount an existing JuiceFS Volume by name.
How it works
After the volume is mounted, the Sandbox accesses JuiceFS through file paths, and the data is not deleted when the Sandbox is released.
To provide the complete JuiceFS configuration when you create a Sandbox, see Mount JuiceFS dynamically.
To append a mount to a running Sandbox, see Append a volume mount.
Prerequisites
-
You have created a JuiceFS Volume for the target team and obtained the volume name.
-
You have prepared an Agent Sandbox API key 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, all of which can reach the JuiceFS service.
-
You have prepared the Agent Sandbox API URL, the domain, and a custom template of the second-generation runtime (MicroVM).
The VPC configuration used to create the Sandbox must contain vpcId, securityGroupId, and a non-empty vSwitchIds, and must be able to access the target storage. The VPC configuration in the 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 automatically installs the JuiceFS Enterprise Edition client, the RADOS (Reliable Autonomic Distributed Object Store) runtime library, and FUSE 2 (Filesystem in Userspace) that the mount requires. RADOS is the underlying object store of Ceph. 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 storage clients that this topic requires into the template image, together with their dependencies. They are the JuiceFS Enterprise Edition client, the RADOS runtime library, and FUSE 2. 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. 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 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 a template that meets the prerequisites. Obtain the value in the Agent Sandbox console. |
|
|
The name of the JuiceFS Volume to mount. |
Use the name that you set when you created the JuiceFS Volume, or query the name in the volume list. Do not use the volume ID. |
In volume_mounts, specify the name of the JuiceFS Volume, which is the value of JUICEFS_SANDBOX_VOLUME_NAME. Do not use the JuiceFS file system name or 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="<MICROVM-TEMPLATE-ID>"
export JUICEFS_SANDBOX_VOLUME_NAME="juicefs-workspace"
The local mount directory resides in the Sandbox and corresponds to the key of volume_mounts. A subdirectory of /home
, /mnt
, /tmp
, or /data
is recommended. This topic uses /mnt/juicefs.
The following example reuses the mountConfig.vpcConfig of the volume to mount the JuiceFS Volume to /mnt/juicefs. Make sure that the volume stores a complete VPC configuration.
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 04_mount_juicefs_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/juicefs"
marker_path = f"{mount_dir}/hello-juicefs-{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("JUICEFS_SANDBOX_VOLUME_NAME"),
},
)
info = sandbox.get_info()
print(f"volume_mounts={info.volume_mounts}")
sandbox.files.write(marker_path, "hello juicefs\n")
marker_written = True
content = sandbox.files.read(marker_path)
if content != "hello juicefs\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("JuiceFS Volume read/write verification passed")
Run the example:
python 04_mount_juicefs_volume.py
If the output shows JuiceFS 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 or the JuiceFS file system name. -
Based on the volume name, Agent Sandbox reads the
volumeName,baseURL,remoteDir,token, andargsstored when the volume was created. Agent Sandbox then converts these values into the JuiceFS mount configuration. -
This topic reuses the
mountConfig.vpcConfigof the volume. To override it, provide a complete VPC configuration in the metadata of the Sandbox creation request by usingfc.sandbox.network.vpc. If both are configured, the metadata takes precedence. -
When a Sandbox is resumed after it is paused, the volume mount is restored.
-
Releasing a Sandbox does not delete the data in JuiceFS. The test file is deleted by the example. The retention and cleanup of other data must be handled separately.
Limits
-
In the same Sandbox, JuiceFS supports a maximum of five 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.. -
Mount directories cannot be duplicated in the same Sandbox.
-
All JuiceFS mounts in the same Sandbox must use the same
baseURL. This requirement applies to both the mounts that reference volumes by name and the mounts that specify the storage configuration directly.
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.
The VPC is configured, but why does the system report that the configuration is incomplete
If the error message contains mount requires complete VPC config, the VPC configuration used in this creation is missing required fields.
If you do not specify the VPC in the metadata, check the mountConfig.vpcConfig of the volume. If you specify it, check fc.sandbox.network.vpc. The configuration actually used must contain vpcId, securityGroupId, and a non-empty vSwitchIds. The metadata configuration takes precedence, and the fields of the volume are not used to fill in an incomplete metadata configuration.
The volume is created, but Sandbox creation times out or the mount fails
Creating a volume only stores the configuration and does not perform the actual mount. Check the corresponding configuration based on the error message. If the message does not clearly indicate the cause, troubleshoot in the following order:
-
Verify the JuiceFS Enterprise Edition client, the RADOS runtime library, and FUSE 2 as described in Step 1: Pre-install storage clients when you create a template in this topic.
-
Check the VPC routes, security groups, and service addresses actually used, and confirm that the Sandbox can access the JuiceFS service.
-
Check the token, the file system name, and the remote directory, and confirm that the token allows access to the target directory.
To troubleshoot further, retain the complete error message and the request ID.