Skip to content

datalayer/code-sandboxes

Repository files navigation

Datalayer

Become a Sponsor

{ } Code Sandboxes

PyPI - Version

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

Canonical variant names:

  • jupyter
  • docker
  • eval
  • monty
  • kaggle
  • colab
  • modal
  • datalayer

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/installation and https://code-sandboxes.datalayer.tech/sandboxes.

Quick Examples

Python: launch a 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

CLI REPL: kaggle variant

Kaggle REPL supports both interactive runtime mode and credential-based batch mode.

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
sandbox repl --variant kaggle

For full setup and parameters for all variants, see:

License

BSD 3-Clause License

Sponsor this project

Contributors

Languages