Jupyter Environment
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 . serverThe 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-envConfiguration
E2B_API_KEY: required when resetting an episode.MAX_CONCURRENT_ENVS: maximum concurrent WebSocket sessions. Defaults to4.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 submit_paths closes that, per environment and per task.
Verifying outside the agent’s sandbox
A task that passes submit_paths to reset is verified in a second sandbox the
agent never touches. The list defaults to empty, and an empty list keeps the
behaviour above, so existing tasks score exactly as before.
With paths declared, submitting runs this order, which is what makes it a boundary rather than hardening:
- A fresh sandbox is created from the same template.
- The task’s
setupcommands run there, before any of the agent’s work exists. - The declared paths are copied out of the agent’s sandbox into
/submission, which is not the working directory and is not onPATHorPYTHONPATH. - The verify commands run, and the reward file is cleared and read there.
- The sandbox is killed.
Paths are relative to /home/user. An absolute path, one that leaves the
workspace with .., a symlink, a socket, a fifo, a device, or a submission over
200 files or 10 MiB is refused, and the reason is recorded in state.submission_refused. Files that a shell or a test runner reads before the
first assertion are left behind even when a declared directory contains them:
the login files a shell reads (.bash_profile, .bash_login, .profile, .bashrc, .bash_logout), what Python runs before an import
(sitecustomize.py, usercustomize.py, *.pth, conftest.py), and every
file pytest takes options from (pytest.ini, .pytest.ini, pytest.toml, .pytest.toml, pyproject.toml, setup.cfg, tox.ini), since any of them can carry addopts = --co and report success
without running a test. Declaring one of those exactly still submits it, since
naming it is the task author’s decision.
Because the submission is no longer in the workspace, a task that opts in writes
its verify commands against /submission. The task’s own test files keep coming
from its setup commands, so the copy cannot replace them.
The boundary covers what the agent leaves in its own sandbox, not the code it submits. A verify command that imports or runs the submission runs that code as root in the verifier sandbox, where it can do anything root can, including ending the test process with status 0 and writing the reward file.
The cost is one extra sandbox per scored rollout, which is why it is opt-in rather than the default.
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.
Update on GitHub