Running external commands in kernel

Hi all,

I have an idea of creating extension for JupyterLab which will allow to run VNC session next to the running kernel. And kernel itself can be spawned on remote host via Jupyter Enterprise Gateway.

So under the hood it will be an extension which can be activated via NotebookApp.nbserver_extensions and will add /vnc endpoint in Lab.

The extension will have a REST API to start/stop and monitor remote VNC server. To allow JS/TS part of the Lab to operate and run NoVNC it will provide websocket forwarded to the port on the remote host, like
/vnc/{kernel_id}/ws -> compute-host:9100

Apparently VNC server should be running in kernel context. So I need to have a method to execute vncserver and vncserver -kill on the remote host.

Unfortunately, I can’t use kernel_manager.get_kernel(kernel_id).client() instance when EG in use: kernel_manager.get_kernel(kernel_id) call returns dict, but not kernel object.

So I can think of issuing direct commands using Jupyter Messaging Protocol, something like "content": {"code": "Popen('vncserver')"}' which sent on ws://localhost:{kernel_port}{base_url}/api/kernels/{kernel_id}/channels?token={token}

But I am a bit afraid of messing up with user input. The kernel might be in busy state, and it seems like I have no way to check it before issuing execute_request message.

Another option is to use comm-s - seems pretty safe, but relies on kernel’s facilities. Module to handle my calls should be available on the remote host and registered in kernel.
Another drawback is that I am not sure is it possible to use comms in Rlang for example, or scala, or other kernels.

So I need someone to talk with :slight_smile: