Repository navigation
feat: isolate Jupyter behind a private Unix socket #343
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
3132c2b
feat: isolate Jupyter behind a private Unix socket
devin-ai-integration[bot] 361f055
docs: omit internal Jupyter transport details
devin-ai-integration[bot] b67d0bf
ci: run interpreter tests in a separate workflow
devin-ai-integration[bot] 75479f0
fix: probe Jupyter over its private socket in debug logs
devin-ai-integration[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| name: Interpreter Server Tests | ||
|
|
||
| on: | ||
| pull_request: | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| test: | ||
| name: Interpreter Server Tests | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 10 | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 | ||
|
|
||
| - name: Parse .tool-versions | ||
| uses: wistia/parse-tool-versions@32f568a4ffd4bfa7720ebf93f171597d1ebc979a # v2.1.1 | ||
| with: | ||
| filename: '.tool-versions' | ||
| uppercase: 'true' | ||
| prefix: 'tool_version_' | ||
|
|
||
| - name: Install uv | ||
| uses: astral-sh/setup-uv@d0cc045d04ccac9d8b7881df0226f9e82c39688e # v6.8.0 | ||
| with: | ||
| version: '${{ env.TOOL_VERSION_UV }}' | ||
| python-version: '${{ env.TOOL_VERSION_PYTHON }}' | ||
| enable-cache: true | ||
|
|
||
| - name: Test interpreter server | ||
| run: uv run --with-requirements template/requirements-test.txt pytest template/tests |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| [pytest] | ||
| pythonpath = server | ||
| asyncio_mode = auto | ||
| testpaths = tests |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| -r server/requirements.txt | ||
| pytest==9.0.3 | ||
| pytest-asyncio==1.3.0 | ||
| jupyter-server==2.20.0 | ||
| ipykernel==6.31.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| JUPYTER_BASE_URL = "http://localhost:8888" | ||
| JUPYTER_SOCKET_PATH = "/run/e2b-jupyter/server.sock" | ||
| JUPYTER_BASE_URL = "http://localhost" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| import asyncio | ||
| import os | ||
| import socket | ||
| import sys | ||
| from pathlib import Path | ||
|
|
||
| import httpx | ||
| from anyio import fail_after | ||
|
|
||
| import envs | ||
| import messaging | ||
| from api.models.output import OutputType | ||
| from messaging import ContextWebSocket | ||
|
|
||
|
|
||
| async def test_jupyter_http_and_execution_use_unix_socket_only(tmp_path, monkeypatch): | ||
| path = str(tmp_path / "jupyter.sock") | ||
| config = Path(__file__).resolve().parents[1] / "jupyter_server_config.py" | ||
| monkeypatch.setattr(messaging, "JUPYTER_SOCKET_PATH", path) | ||
| monkeypatch.setattr(envs, "LOCAL", True) | ||
| with (tmp_path / "jupyter.log").open("w+") as logs: | ||
| process = await asyncio.create_subprocess_exec( | ||
| sys.executable, | ||
| "-m", | ||
| "jupyter_server", | ||
| f"--config={config}", | ||
| f"--ServerApp.sock={path}", | ||
| f"--ServerApp.root_dir={tmp_path}", | ||
| "--IdentityProvider.token=", | ||
| stdout=logs, | ||
| stderr=logs, | ||
| env={ | ||
| **os.environ, | ||
| "IPYTHONDIR": str(tmp_path / "ipython"), | ||
| "JUPYTER_RUNTIME_DIR": str(tmp_path), | ||
| }, | ||
| ) | ||
| ws = None | ||
| try: | ||
| async with httpx.AsyncClient( | ||
| transport=httpx.AsyncHTTPTransport(uds=path), | ||
| base_url="http://localhost", | ||
| trust_env=False, | ||
| ) as client: | ||
| with fail_after(30): | ||
| while True: | ||
| if process.returncode is not None: | ||
| logs.seek(0) | ||
| raise AssertionError(logs.read()) | ||
| try: | ||
| response = await client.get("/api/status") | ||
| if response.status_code == 200: | ||
| break | ||
| except httpx.RequestError: | ||
| pass | ||
| await asyncio.sleep(0.1) | ||
|
|
||
| assert Path(path).stat().st_mode & 0o777 == 0o600 | ||
| with socket.socket() as tcp: | ||
| assert tcp.connect_ex(("127.0.0.1", 8888)) != 0 | ||
|
|
||
| response = await client.post("/api/kernels", json={"name": "python3"}) | ||
| response.raise_for_status() | ||
| kernel_id = response.json()["id"] | ||
| ws = ContextWebSocket(kernel_id, "session", "python", str(tmp_path)) | ||
| await ws.connect() | ||
| with fail_after(30): | ||
| outputs = [item async for item in ws.execute("6 * 7", {}, None)] | ||
| assert any( | ||
| item["type"] == OutputType.RESULT and item["text"] == "42" | ||
| for item in outputs | ||
| ), outputs | ||
| outputs = [] | ||
| with fail_after(10): | ||
| async for item in ws.execute( | ||
| 'print("started", flush=True)\nimport time\ntime.sleep(60)', | ||
| {}, | ||
| None, | ||
| ): | ||
| outputs.append(item) | ||
| if item["type"] == OutputType.STDOUT: | ||
| await ws.interrupt() | ||
| assert any( | ||
| item["type"] == OutputType.ERROR | ||
| and item["name"] == "KeyboardInterrupt" | ||
| for item in outputs | ||
| ), outputs | ||
| assert ( | ||
| await client.delete(f"/api/kernels/{kernel_id}") | ||
| ).status_code == 204 | ||
| finally: | ||
| if ws is not None: | ||
| await ws.close() | ||
| if process.returncode is None: | ||
| process.terminate() | ||
| await process.wait() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.