opensi·si

jupyterenv exposes a stateful Jupyter-style Python notebook through MCP

Jupyter

jupyter_env exposes a stateful Jupyter-style Python notebook through MCP tools. Each episode creates a fresh E2B Code Interpreter sandbox, so Python variables, imports, files, and generated plots persist across tool calls until the next reset.

Reset can also receive setup and verify scripts. Setup commands run immediately after the sandbox is created. Verify commands are stored for the episode and run when the agent calls final_answer.

Tools

  • add_and_execute_code_cell(code): execute a new Python cell.
  • edit_and_execute_current_cell(code): replace and re-run the latest code cell.
  • execute_shell_command(command): run shell commands inside the sandbox.
  • get_notebook_state(include_images=False): summarize recent notebook cells.
  • final_answer(answer): record a final answer and run any configured verify commands.

Quick Start

from jupyter_env import JupyterEnv

with JupyterEnv(base_url="http://localhost:8000").sync() as env:
    env.reset(
        setup=["pip install -q pandas"],
        verify=[
            "python - <<'PY'\nfrom pathlib import Path\nassert Path('/home/user/work/answer.txt').exists()\nPY"
        ],
    )
    print(env.call_tool("add_and_execute_code_cell", code="x = 21 * 2\nx"))
    print(env.call_tool("final_answer", answer="done"))

Local Server

cd envs/jupyter_env
E2B_API_KEY=e2b_... uv run --project . server

The API and custom web UI are served on port 8000. The notebook UI is mounted at /web.

Docker

cd envs/jupyter_env
openenv build -t jupyter-env
docker run -p 8000:8000 -e E2B_API_KEY=e2b_... jupyter-env

Configuration

  • E2B_API_KEY: required when resetting an episode.
  • MAX_CONCURRENT_ENVS: maximum concurrent WebSocket sessions. Defaults to 4.
  • KAGGLE_DATA_DIR: optional root directory for reset-time Kaggle file staging.

Setup and Verify Commands

reset() accepts either setup / verify or setup_scripts / verify_scripts.

env.reset(
    setup=[
        "mkdir -p /home/user/work",
        "printf 'seed data' > /home/user/work/input.txt",
    ],
    verify=[
        "test -f /home/user/work/answer.txt",
        "python -m pytest /home/user/work/tests",
    ],
)

Setup failure ends the reset response with done=True and returns the captured setup results. Verify commands run when final_answer(answer) is called. Reward defaults to passed_verify_commands / total_verify_commands. A verify command can override this by writing a float to:

/home/user/logs/verifier/reward.txt

The file is deleted before the verify commands run, so only a verify command can set it; anything the agent writes there earlier is discarded. The value must be a finite number; a verify command is written by the task author, so negative rewards and values above 1 are accepted too. A value that is not a finite number is ignored, the pass rate is used, and the reason is recorded in state.reward_override_ignored.

Verify commands, the clearing of that file and the read of it run as their own sandbox processes through E2B's process API, as root in /home/user, rather than inside the notebook kernel. A cell can rebind subprocess.run, change the working directory or edit os.environ, and none of that reaches verification. This removes the coupling to the kernel; it does not isolate verification from the agent. The notebook kernel runs as root in E2B's default code-interpreter template, so agent code can still change anything in the sandbox, including the files a verify command reads and the startup files of the shell it runs in. E2B starts each command as a login shell, so a profile the agent writes decides what a verify command reports: an exit 0 or an EXIT trap in /root/.bash_profile makes a failing command look like a passing one. A test pins that behaviour rather than leaving it to be found in a reward curve, and #1232 tracks verification outside the agent's sandbox, which is what closes it.

Only a command that ran and exited decides a verify result. If the sandbox itself fails, because it cannot be reached, the command cannot be started, or the wait for it ends without an exit status, the error is raised instead: verification stops, no reward is produced, and the episode does not finish. A sandbox that is unreachable, expired or unauthenticated says nothing about the agent's work, and a command with no exit status may still be running, since E2B's kill signals the command's own process and not the children it started.

Notes

This first version intentionally keeps sandbox provider selection local to the environment and uses E2B as the concrete backend. A shared OpenEnv sandbox API can be introduced later once the provider contract is RFC-backed.