{ } 📦 Code Sandboxes
Code Sandboxes (code_sandboxes) is a Python package for running code in isolated sandbox variants through a unified API.
Canonical variant names:
datalayerdockerevalgoogle_colabjupyterkagglemodalmonty
Documentation
The full documentation is the single source of truth:
- Docs home: https://code-sandboxes.datalayer.tech
- Sandboxes and variant setup: https://code-sandboxes.datalayer.tech/sandboxes
- Installation: https://code-sandboxes.datalayer.tech/installation
- CLI usage: https://code-sandboxes.datalayer.tech/cli
- API reference: https://code-sandboxes.datalayer.tech/api-reference
- Examples: https://code-sandboxes.datalayer.tech/examples
- Comparison: https://code-sandboxes.datalayer.tech/comparison
Published site:
Install
pip install code-sandboxes
For backend-specific extras and credentials, see https://code-sandboxes.datalayer.tech/installation and https://code-sandboxes.datalayer.tech/sandboxes.
Jupyter Sandbox
from code_sandboxes import Sandbox
# Option 1: manage a local Jupyter server automatically
with Sandbox.create(variant="jupyter") as sandbox:
print(sandbox.run_code("1 + 1").text) # 2
# Option 2: connect to an existing Jupyter server
with Sandbox.create(
variant="jupyter",
server_url="http://localhost:8888",
token="MY_TOKEN",
) as sandbox:
sandbox.run_code("x = 40")
print(sandbox.run_code("x + 2").text) # 42
Kaggle Sandbox
Kaggle supports both batch execution and interactive connections through the
kaggle sandbox. Install its optional dependency first:
pip install "code-sandboxes[kaggle]"
Required credentials for batch mode:
~/.kaggle/kaggle.json, orKAGGLE_API_KEY
# Install Kaggle support
pip install code-sandboxes[kaggle]
# Optional: env-based credentials (if not using ~/.kaggle/kaggle.json)
export KAGGLE_API_KEY="<your-kaggle-api-key>"
# Launch the REPL
sandbox repl --variant kaggle
For batch execution, configure Kaggle credentials and create the sandbox without a runtime URL:
from code_sandboxes import Sandbox
with Sandbox.create(variant="kaggle") as sandbox:
result = sandbox.run_code("print('hello from kaggle')")
print(result.stdout)
The lower-level batch API is also available directly:
from code_sandboxes import KaggleKernelExecutor
executor = KaggleKernelExecutor()
result = executor.execute(
"print('hello from kaggle')",
title="code-sandboxes-demo",
accelerator="NvidiaTeslaT4",
wait=True,
)
print(result.status, result.stdout)
print(result.to_kernel_reply())
For interactive execution, copy the WebSocket channels URL from an active Kaggle notebook session and pass it to the sandbox or client:
from code_sandboxes import KaggleKernelClient
with KaggleKernelClient.from_channels_url(channels_url, token=None) as kernel:
print(kernel.execute("x = 1 + 1; print(x)"))
See the complete Kaggle guide for authentication, accelerators, channels URL retrieval, and execution options.
Google Colab
Google Colab exposes an already-running kernel through an authenticating proxy. Copy its WebSocket channels URL from the browser's Network tools, then pass it directly to the sandbox:
from code_sandboxes import Sandbox
with Sandbox.create(variant="google_colab", channels_url=channels_url) as sandbox:
print(sandbox.run_code("x = 1 + 1; print(x)").stdout)
The lower-level client and parser are owned by Code Sandboxes as well:
from code_sandboxes import GoogleColabKernelClient, parse_google_colab_channels_url
server_url, kernel_id, proxy_token = parse_google_colab_channels_url(channels_url)
with GoogleColabKernelClient.from_channels_url(channels_url) as kernel:
print(kernel.execute("print('hello from colab')"))
See the complete Google Colab guide for proxy authentication, explicit connection values, and channels URL retrieval.
License
BSD 3-Clause License
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file code_sandboxes-1.0.8-py3-none-any.whl.
File metadata
- Download URL: code_sandboxes-1.0.8-py3-none-any.whl
- Upload date:
- Size: 82.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
efcc2b2fd85cb0d85f325a744f0f903d7259835454cb40f6e6a6f1a911359074
|
|
| MD5 |
41f218f239473a63709f45e009fab4c1
|
|
| BLAKE2b-256 |
a482dbca43ed9f75e9552fcfeccd3ab28a9bd8d37f9918f3b4c2f0d4ee936eb4
|