Skip to main content

Execute code on a remote JupyterHub kernel from any terminal — zero dependencies.

Project description

jupyterhub-exec

Execute code on a remote JupyterHub kernel from any terminal — zero external dependencies.

pip install jupyterhub-exec

Why

JupyterHub provides GPU compute. Your agent terminal does not. jh-exec bridges the two using the Jupyter kernel protocol over a raw WebSocket — no browser, no notebook UI, no library dependencies beyond the Python standard library.

┌─────────────────────────┐        WebSocket         ┌──────────────────────────┐
│   Agent Terminal (CPU)  │ ───────────────────────► │  JupyterHub Kernel (GPU) │
│   Claude Code / CLI     │ ◄─────────────────────── │  PyTorch / CUDA          │
└─────────────────────────┘        stdout stream      └──────────────────────────┘

Usage

# Execute a script on the remote GPU kernel
jh-exec run train.py

# Execute inline code
jh-exec exec "import torch; print(torch.cuda.is_available())"

# List running kernels
jh-exec kernels

# Start a new kernel
jh-exec new-kernel

Configuration

Set via environment variables or a .env file in the working or home directory:

Public JupyterHub (HTTPS — default):

JH_HOST=https://hub.example.com
JH_USER=agent-01
JH_TOKEN=your_token_here
JH_TIMEOUT=600

Local JupyterHub (HTTP):

JH_HOST=http://192.168.1.100:8000
JH_USER=agent-01
JH_TOKEN=your_token_here
JH_TIMEOUT=600

Or pass directly:

jh-exec --host https://hub.example.com --user agent-01 --token your_token run script.py

Python API

from jh_exec import execute, list_kernels, new_kernel

# Execute code, stream output to stdout
execute("import torch; print(torch.cuda.get_device_name(0))")

# List running kernels
kernels = list_kernels()

# Start a new kernel, get its ID
kid = new_kernel()

Dedicated GPU per agent

In jupyterhub_config.py:

def assign_gpu(spawner):
    gpu_map = {
        "agent-01": "0",
        "agent-02": "1",
        "agent-03": "2",
    }
    spawner.environment["CUDA_VISIBLE_DEVICES"] = gpu_map.get(spawner.user.name, "")

c.Spawner.pre_spawn_hook = assign_gpu

Benchmark

Validated on NVIDIA GeForce GTX TITAN X via gpu_demo.py:

GPU: NVIDIA GeForce GTX TITAN X  (11.9 GiB)  torch 2.5.1+cu121
8192x8192 matmul: 235.9 ms  (4.7 TFLOP/s)
checksum: 890989.3125
allocated: 776 MiB

Full GPU offload from a Claude Code terminal — zero local GPU, zero dependencies.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jupyterhub_exec-0.1.3.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

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

jupyterhub_exec-0.1.3-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file jupyterhub_exec-0.1.3.tar.gz.

File metadata

  • Download URL: jupyterhub_exec-0.1.3.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.2

File hashes

Hashes for jupyterhub_exec-0.1.3.tar.gz
Algorithm Hash digest
SHA256 6ae7003cfce9cb32d82f0d620fba04f53e0c5ed59a7471376964d8577cfc0bc6
MD5 431e4df6b4502cf3b49956feb4e2a838
BLAKE2b-256 02378c1fc07e1fbf891da2b80b1e80248280a6a4d24dcd44b33652c86743af8f

See more details on using hashes here.

File details

Details for the file jupyterhub_exec-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for jupyterhub_exec-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 02f0fdac1824bba3358508d33849f9bf06f8eeda3ada21a0d0fe6f8fc9312d37
MD5 2a3c0c3e38dff2c40a64393b7dce446a
BLAKE2b-256 1d9d48f60a24d1c2f24352ce6ebfc5ea4f039d258c40d9cd5e5225389046dcb6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page