A notebook in the sandbox
Data analysis agents work best when people can see the work. Start JupyterLab in the python template, expose its port, and the user opens the agent's notebook at a private HTTPS URL while the agent keeps working in the same sandbox.
import secretsfrom cpuos import Sandboxsbx = Sandbox.create(template="python", timeout="1h")sbx.exec("uv pip install --system jupyterlab", timeout="5m")token = secrets.token_urlsafe(24)sbx.exec( "jupyter lab --ip=0.0.0.0 --port=8888 --no-browser " f"--IdentityProvider.token={token} --notebook-dir=/work", background=True,)print(f"{sbx.url(8888)}/lab?token={token}")Always set a token. The URL is private to your sandbox, but a notebook server is remote code execution by design, so treat the link like a password. For a template that starts faster, bake JupyterLab into a custom template.
cpuos is in early access: @cpuos/sdk (npm) and cpuos (PyPI) ship to early-access teams first, and read the API key from CPUOS_API_KEY. The calls on this page show the current API shape.
Let the agent write notebooks
Instead of loose scripts, the agent can append cells to /work/analysis.ipynb and execute the notebook with jupyter nbconvert --to notebook --execute --inplace. The result is a notebook with code, outputs and charts that the user can open, read and rerun.
run = sbx.exec( "cd /work && jupyter nbconvert --to notebook --execute --inplace analysis.ipynb", timeout="5m",)if run.exit_code != 0: feedback = run.stderr[-3000:] # send the traceback back to the modelThe model that writes the cells can run on your own GPUs: point the OpenAI Python SDK at gpuOS and keep the loop from the code interpreter guide.
Official documentation: jupyter.org