Skip to main content

Datalayer

Become a Sponsor PyPI - Version

{ } 📦 Code Sandboxes

Code Sandboxes (code_sandboxes) is a Python package for running code in isolated sandbox variants through a unified API.

Canonical variant names:

  • cloudflare
  • coreweave
  • datalayer
  • daytona
  • docker
  • e2b
  • eval
  • google-colab
  • jupyter-server
  • kaggle
  • modal
  • monty

Documentation

The full documentation is the single source of truth:

Published site:

Install

pip install code-sandboxes

For backend-specific extras and credentials, see https://code-sandboxes.datalayer.tech/install and https://code-sandboxes.datalayer.tech/providers.

Jupyter Server Sandbox

from code_sandboxes import Sandbox

# Option 1: manage a local Jupyter server automatically
with Sandbox.create(variant="jupyter-server") as sandbox:
  print(sandbox.run_code("1 + 1").text)  # 2

# Option 2: connect to an existing Jupyter server
with Sandbox.create(
  variant="jupyter-server",
  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, or
  • KAGGLE_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
code-sandboxes 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.

Manage Sandboxes (CRUD)

Every variant answers the same verbs — create, list, get, update, delete — from Python or from the CLI, rendered as rich tables:

code-sandboxes list                 # every variant that answers, one table
code-sandboxes list -v kaggle       # one variant
code-sandboxes get <id> -v modal    # one sandbox, live status
code-sandboxes create -v modal      # create detached, leave it running
code-sandboxes update <id> -v modal --tag team=ai   # tags (modal), --name
                                    # (docker), --capability (datalayer),
                                    # --code (kaggle: a new version)
code-sandboxes delete <id> -v modal --yes
code-sandboxes environments         # what sandboxes can be created in
from code_sandboxes import get_manager

manager = get_manager("modal")
for info in manager.list():
    print(info.id, info.status)
manager.delete("sb-...")

See the management guide for what each variant maps to and its connection settings.

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

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

code_sandboxes-1.1.4-py3-none-any.whl (153.8 kB view details)

Uploaded Python 3

File details

Details for the file code_sandboxes-1.1.4-py3-none-any.whl.

File metadata

  • Download URL: code_sandboxes-1.1.4-py3-none-any.whl
  • Upload date:
  • Size: 153.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.11

File hashes

Hashes for code_sandboxes-1.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 d5e86d6d4c446124ac2c41e58de78fc689d556bde5f3018eae6bfb0ab938c7c2
MD5 f982d887dbb63e48622a0992d8615adb
BLAKE2b-256 2072c0e72062e0d4f8aa25fbd2f8338f816ac292eb695b5766a5698104f3148c

See more details on using hashes here.

Release history Release notifications | RSS feed

1.4.3

1 file

1.4.2

1 file

1.4.1

1 file

1.4.0

1 file

1.3.0

1 file

1.2.2

1 file

1.2.1

1 file

This release

1.1.4 This release

1 file

1.1.2

1 file

1.1.1

1 file

1.1.0

1 file

1.0.10

1 file

1.0.9

1 file

1.0.8

1 file

1.0.7

1 file

1.0.6

1 file

1.0.5

1 file

1.0.4

1 file

1.0.3

1 file

1.0.2

1 file

1.0.1

1 file

1.0.0

1 file

0.17.0

1 file

0.16.0

1 file

0.0.21

1 file

0.0.20

1 file

0.0.19

1 file

0.0.18

1 file

0.0.17

1 file

0.0.16

1 file

0.0.15

1 file

0.0.14

1 file

0.0.13

1 file

0.0.12

1 file

0.0.11

1 file

0.0.10

1 file

0.0.9

1 file

0.0.8

1 file

0.0.7

1 file

0.0.6

1 file

0.0.5

1 file

0.0.4

1 file

0.0.3

1 file

0.0.2

1 file

0.0.1

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page