Datalayer
Cloud-based execution with full isolation, GPU support, snapshots, and persistence.
- Requirements:
code-sandboxes[datalayer](installsagent_runtimes). - Parameters:
token(defaults toDATALAYER_API_KEY),run_url,snapshot_name, plus creation options likeenvironment,gpu,cpu,memory.
How To Obtain Datalayer Credentials​
- Create an account at datalayer.ai.
- Generate an API token from your account settings (IAM → Tokens / API Keys).
- Export
DATALAYER_API_KEY(or pass it as thetokenparameter). SetDATALAYER_RUN_URLonly for a self-hosted / custom deployment.
Usage​
import os
from code_sandboxes import Sandbox
os.environ["DATALAYER_API_KEY"] = "your-datalayer-token"
with Sandbox.create(
variant="datalayer",
gpu="A100",
environment="python-gpu-env",
) as sandbox:
sandbox.run_code("import torch; print(torch.cuda.is_available())")
The concrete implementation is available from a top-level module:
from code_sandboxes.datalayer_sandbox import DatalayerSandbox
Snapshots​
Save and restore sandbox state (datalayer only):
with Sandbox.create(variant="datalayer") as sandbox:
# Set up environment
sandbox.run_code("import pandas as pd")
sandbox.run_code("df = pd.DataFrame({'a': [1,2,3]})")
# Create snapshot
snapshot = sandbox.create_snapshot("my-setup")
print(f"Snapshot: {snapshot.id}")
# Later: restore from snapshot
with Sandbox.create(
variant="datalayer",
snapshot_name="my-setup"
) as sandbox:
result = sandbox.run_code("print(df)") # State restored