Thanks to visit codestin.com
Credit goes to code-sandboxes.datalayer.tech

Skip to main content

Examples

The Daytona, E2B, and Modal exec and repl examples use a real Jupyter Server over provider ingress by default. Pass --direct to use the provider SDK adapter instead. See Jupyter over Provider Ingress.

The repository carries a runnable example for every variant, in two sets that differ only in what they do with the sandbox once it is open.

SetWhat it doesEntry point
examples/execRuns a handful of snippets, prints what came back, and exits 1 if any of them failed. Read this one first.show_and_run
examples/replOpens the same sandbox and hands you a prompt to type into.run_repl

Both are built on what the package exports, and it is the same code behind code-sandboxes exec and code-sandboxes repl — so an example is a readable version of what the CLI does, not a separate demonstration. See the CLI.

Running One​

Each set has a Makefile with one target per variant, named after it:

cd examples/exec
make eval # runs in this very process — needs nothing at all
make docker # needs a Docker daemon
make e2b # needs E2B_API_KEY

A target whose credentials are missing stops at once, naming what it wants, rather than failing somewhere in the middle. make all runs the targets in sequence and therefore stops at the first one you are not set up for — it is a way to run the local ones, not a way to run everything.

The variants that can take a GPU have a second target for it:

make modal-gpu # MODAL_GPU, default T4
make daytona-gpu # DAYTONA_GPU, default H100
make daytona-gpu-spot # the same on preemptible capacity
make coreweave-gpu # COREWEAVE_GPU, default H100
make kaggle-gpu # KAGGLE_GPU, default T4

:examples, Once You Are In​

Every REPL example answers :examples at its prompt: a handful of snippets to copy straight in, chosen for the sandbox you actually opened. A GPU run offers device discovery and a timed matmul; a plain one offers state, packages and files; the Cloudflare one demonstrates its own statelessness and the two ways round it.

sandbox(daytona:tan-law-5384)>>> :examples

# 1. What the GPU is, straight from the driver
import subprocess
print(subprocess.run(["nvidia-smi"], capture_output=True, text=True).stdout)
...

Each line stands on its own, because the prompt reads one at a time — so a whole snippet can be pasted at once.

What Each One Needs​

Nothing here is a substitute for the per-variant pages — this is only enough to pick one to run. The credentials themselves are documented under Providers, and the extras under Installation.

VariantTargetNeedsExtra
Evalmake evalnothing—
Montymake montynothing[monty]
Dockermake dockera Docker daemon[docker]
Jupyter Servermake jupyter-servernothing — a local Jupyter Server is started for you—
Datalayermake datalayerDATALAYER_API_KEY[datalayer]
E2Bmake e2bE2B_API_KEY[e2b]
Modalmake modalMODAL_TOKEN_ID + MODAL_TOKEN_SECRET[modal]
Daytonamake daytonaDAYTONA_API_KEY[daytona]
CoreWeavemake coreweaveCWSANDBOX_API_KEY[coreweave]
Cloudflaremake cloudflarea deployed bridge Worker[cloudflare]
Kagglemake kaggleKAGGLE_API_TOKEN, or ~/.kaggle/kaggle.json[kaggle]
Google Colabmake google-colabRUNTIME_URL, RUNTIME_ID, RUNTIME_PROXY_TOKEN from a Colab session—

Two Worth Reading Rather Than Only Running​

Most of the examples say the same thing in the same shape, because most of the variants behave the same way. Two do not, and the difference is the point:

  • Cloudflare demonstrates a stateless provider: it shows x = 1 in one snippet failing to be there in the next, and then both ways round it — putting what shares state into one snippet, or keeping it in a file, which does persist.
  • E2B demonstrates the opposite end: a kernel that keeps its namespace, an HTML result coming back as HTML rather than as the text of a repr, and the two things only this variant offers — set_timeout and get_host(port).
  • Providers — what each variant needs, in full
  • Installation — the extras
  • CLI — the commands the examples are built on