Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/opensandbox-group/OpenSandbox/llms.txt

Use this file to discover all available pages before exploring further.

OpenSandbox exposes a runtime-neutral Volume abstraction that lets you attach persistent or shared storage to any sandbox. Depending on your deployment target — Docker, Kubernetes, or a host machine — you choose the appropriate backend: pvc for Docker named volumes and Kubernetes PersistentVolumeClaims, ossfs for Alibaba Cloud OSS buckets, or host for bind-mounting a directory from the host filesystem. All backends share the same SDK shape, so switching runtimes requires only a config change.
The pvc backend maps to a Docker named volume on Docker runtimes and to a Kubernetes PersistentVolumeClaim on Kubernetes runtimes. It is the recommended alternative to host-path mounts because Docker manages the storage location and no allowlist is needed.

Why named volumes over host paths?

Host path (host backend)Named volume (pvc backend)
SecurityExposes host filesystem pathsDocker manages storage location; no host path exposed
SetupRequires allowed_host_paths allowlistNo allowlist needed
Cross-sandbox sharingAll containers must agree on a host pathReference the same volume name
PortabilityTied to host directory structureWorks on any Docker host
LifecycleUser manages host directoriesdocker volume create/rm

Scenarios

#ScenarioDescription
1Read-write mountMount a named volume for bidirectional file I/O
2Read-only mountMount a named volume that sandboxes cannot modify
3Cross-sandbox sharingTwo sandboxes share data through the same named volume
4SubPath mountMount only a subdirectory of a named volume (consistent with K8s PVC subPath)

Prerequisites

# Start the server
uv pip install opensandbox-server
opensandbox-server init-config ~/.sandbox.toml --example docker
opensandbox-server

# Create and seed the named volume
docker volume create opensandbox-pvc-demo
docker run --rm -v opensandbox-pvc-demo:/data alpine \
  sh -c "echo 'hello-from-named-volume' > /data/marker.txt"

# Install the Python SDK
uv pip install opensandbox
docker pull ubuntu:latest

Python (async)

from opensandbox import Sandbox
from opensandbox.models.sandboxes import PVC, Volume

sandbox = await Sandbox.create(
    image="ubuntu",
    volumes=[
        Volume(
            name="my-data",
            pvc=PVC(claimName="my-named-volume"),
            mountPath="/mnt/data",
            readOnly=False,           # optional, default is False
            subPath="datasets/train", # optional, mount a subdirectory
        ),
    ],
)

Python (sync)

from opensandbox import SandboxSync
from opensandbox.models.sandboxes import PVC, Volume

sandbox = SandboxSync.create(
    image="ubuntu",
    volumes=[
        Volume(
            name="my-data",
            pvc=PVC(claimName="my-named-volume"),
            mountPath="/mnt/data",
            subPath="datasets/train",  # optional
        ),
    ],
)

TypeScript

import { Sandbox } from "@alibaba-group/opensandbox";

const sandbox = await Sandbox.create({
  image: "ubuntu",
  volumes: [
    {
      name: "my-data",
      pvc: { claimName: "my-named-volume" },
      mountPath: "/mnt/data",
      readOnly: false,
      subPath: "datasets/train",  // optional
    },
  ],
});

Java / Kotlin

Volume volume = Volume.builder()
    .name("my-data")
    .pvc(PVC.of("my-named-volume"))
    .mountPath("/mnt/data")
    .readOnly(false)
    .subPath("datasets/train")  // optional
    .build();

Sandbox sandbox = Sandbox.builder()
    .image("ubuntu")
    .volume(volume)
    .build();

Cleanup

docker volume rm opensandbox-pvc-demo
Run the full scenario script with:
SANDBOX_IMAGE=ubuntu SANDBOX_DOMAIN=localhost:8080 uv run python examples/docker-pvc-volume-mount/main.py

References

Build docs developers (and LLMs) love