Skip to content

Connecting to a remote Jupyter server from vscode.dev

Don Jayamanne edited this page Oct 1, 2023 · 11 revisions

You can connect to a remote Jupyter server from vscode.dev by going into the Kernel Picker of a Notebook and then selecting Select Kernel -> Existing Jupyter Server and then entering the Url

When this quick pick comes up, pick 'Existing Jupyter Server':
Screenshot 2023-04-06 at 05 50 34

On the next step, enter the URI of your Jupyter server:
Screenshot 2023-04-06 at 05 50 41

This should then allow you to pick a kernel from your jupyter server when opening a notebook:

image

Starting your own server

If you're starting this server yourself, there are some special requirements to get it to work in the browser:

Allow_origin

The server has to be started with an 'allow_origin' or 'allow_origin_pat' to allow a browser to connect.

For vscode.dev, this origin is special. You'd start your server with either of the following:

jupyter notebook --no-browser --NotebookApp.allow_origin_pat=https://.*vscode-cdn\.net

or

jupyter notebook --no-browser --NotebookApp.allow_origin='*'.

Using https://vscode.dev as the allow_origin doesn't work because vscode-dev doesn't run extensions at the same URL as the UI. This is a security measure to prevent extensions on different tabs from talking to each other.

If you have the wrong allow_origin set, the Developer Tools console on the browser will show something like so:

image

Allow Access to Private Networks

If Jupyter Server is running on your local machine, your browser might prevent access to this locally running Jupyter application from public websites such as
To address this, the following setting would also need to be configured in the configuration file.

  • Create the configuration file as per the Jupyter Lab documentation
    • Run the following command in the terminal python -m jupyter --generate-config or jupyter --generate-config
    • The full path to the generated configuration file will be printed in the terminal
  • Edit the configuration file to add the following section
c.ServerApp.tornado_settings = {
    'headers': {
        'Access-Control-Allow-Private-Network': 'true',
    },
}

You can learn more about the need for this header here Private Network Access: introducing preflights

Certificate Trust issues

If you're using https, the certificate provided must be trusted by the browser. When this error occurs, the jupyter extension just receives unable to fetch. You can see the results in the network tab for Developer Tools:

image

The way to enable an untrusted certificate is to open the jupyter server's URI in the browser. It should show something like so:

image

If you trust the server (maybe because it's your local machine), you can add this untrusted certificate to the browser. If you reconnect from vscode.dev after that point, it should work.

Logging an issue

If the URL for the server works in the browser, but you still cannot connect, please log an issue.

Clone this wiki locally