VS Code on remote server using https://coder.com/

Remote Visual Studio Code in your browser :grin:

I just found a neat open source project https://coder.com/ that allows you to run the Visual Studio Code IDE on a remote machine and access it through a browser in the same way we use Jupyter.

The github repo for the project is here: https://github.com/cdr/code-server

Set up:

To get it up and running, find the latest release here: https://github.com/codercom/code-server/releases/latest

You can download and run the latest release from the terminal on your remote machine using the following terminal commands:

wget https://github.com/codercom/code-server/releases/download/{version}/code-server-{version}-linux-x64.tar.gz
tar -xvzf code-server-{version}-linux-x64.tar.gz

replace {version} in the above with the appropriate version number e.g. 1.939-vsc1.33.1 is the latest version as I’m writing this.

change directory to the path where you just unzipped to:

cd code-server-{version}-linux-x64

Now you can launch the VS Code server using the command

sudo ./code-server -p {port} &

replacing {port} in the above with the port of your choice - make sure that this is different from the port your Jupyter server is running on (I used 9090).

Remember that you’ll have the above forward this port appropriately in your ssh command. So for example using GCP:

gcloud compute ssh --zone=$ZONE jupyter@$INSTANCE_NAME -- -L 8080:localhost:8080 -L {port}:localhost:{port}

again replacing {port} with the port you chose to run your VS Code server on.

Now you’ll see some output on the command line including a one time password to log into your IDE:

27%20PM

Copy this password, navigate your browser to http://localhost:{port}. You’ll be presented with a prompt to login:

Enter your password and you should get a familiar looking IDE inside your browser :slight_smile:

Bonus - sshcode

https://coder.com/ has also built an awesome command line application that allows you to run VS Code automatically via ssh on a remote server.
https://github.com/cdr/sshcode

They support OSX, Linux, and the Windows (via WSL)

I need to spend some time seeing if I can get this working with GCP - I see that there’s an issue here with some advice on how to do this: https://github.com/cdr/sshcode/issues/2

6 Likes

Now that is cool. What is the latency like?

Thanks for sharing.

1 Like

Seems to work great (as responsive as Jupyter).

I have also got the sshcode version working now too, though it’s a bit of a pain (at least on OSX).

On OSX:
install go programming language:
brew install go

install sshcode

go get -u go.coder.com/sshcode

add sshcode location (should be something like ~/go/bin) to $PATH environment variable

Then if you’re using GCP you have to point it at the appropriate ssh key, so you can call

sshcode --ssh-flags "-i ~/.ssh/google_compute_engine" jupyter@{remote_ip} {remote_directory}

If you’re using GCP {remote_ip} needs to be set to the dynamic IP address that your instance has been allocated which you can find using either the console or the terminal command:

gcloud compute instances list
2 Likes

Microsoft just released something similar. Difference being VScode runs natively on the laptop/desktop instead of the browser. I’ve tried both and this is able to resolve references a little faster.

5 Likes

This is amazing. I just read this post and looking forward to checking it out https://www.brianketelsen.com/vscode-remote-development/

@maral do you need to install vscode both on host machine and the laptop (remote)?

Just laptop. The remote plugin does the rest. Yes it is really amazing.

1 Like

I’ve been using it a bit - works great. With GCP you can run the GCP CLI command gcloud compute config-ssh to create the relevant ssh config file.

Yeah with new development in the library coming up, I’ve started using it last week. It’s super easy to install and amazing!

I was able to successfully run VSCode remotely and it’s great… but only with Python files, i find it to be very unpractical for jupyter notebooks. First, all the referencing in the ipynb notebooks, such as go to definition, etc…, isn’t working (after all the imports). Second, debugging which was my main reason for wanting to use VSCode remotely is not working, even after going through their official instructions. Last, the VSCode jupyter extension is cool, as you can run cells interactively, cell by cell or all, but it is nowhere to be compared to Jupyter’s fluidity.
So, my conclusion is to use it remotely with Python files but not with ipynbs. Now I understand why vim is preferred… Haven’t played much with vim, but I will next. I would love to hear your experience with the above @sgugger and @simonjhb
Thanks

Why would you use VS code for jupyter notebook when you can have them in your browser?

I figured to try it anyway… Mainly for debugging, VSCode tools for debugging are far much better than jupyter pdb debugger, and second referencing/going through source code of some called function within library. These are the two things I dont find friendly in Jupyter and was looking for by trying VSCode remotely. How do you approach them usually @sgugger ?

You can use the set_trace method to debug in jupyter however I agree that debugging vscode is much better.

from IPython.core.debugger import set_trace

I find the internalConsole less annoying to work with (change your launch.json)

 {
            "name": "Run File",
            "type": "python",
            "request": "launch",
            "program": "${workspaceFolder}/test.py",
            "console": "internalConsole"
}

And there is also the %debug magic that lets you inspect the content of any variable when you’ve encountered a bug.

1 Like

Finnaly MS release an extension which let’s you debug vscode everywhere as long as you have an ssh conncetion. Check out VS Code Remote Development

Someone already linked this :slight_smile:

1 Like

Is it possible to use google colab as a remote server? Clouderizer for example lists google colab as one of their available backends.

I’m not familiar with Clouderizer, but looking through their website it seems to me that they are essentially offering an abstraction layer on top of different cloud providers, allowing you to control instances from different providers and providing convenient ways to create new instances and navigate to notebook servers on those instances.

The VS Code Remote Development plugin relies on being able to use an SSH connection to the server. Google colab instances don’t provide a neat way to use the SSH client. However you might be able to hack something together using an idea like this: https://stackoverflow.com/questions/48459804/how-can-i-ssh-to-google-colaboratory-vm

1 Like

Thanks, this is probably what clouderizer is doing as well, but more automated I guess.

Thank you so much for this post. :smiley: