How to create your own VS Code server | by Dimitris Poulopoulos | Towards Data Science

Visual Studio Code is a free, lightweight, and cross-platform code editor. It may not be a full-fledged IDE like IntelliJ Idea or PyCharm, but it is a powerful, distraction-free tool with a dedicated fanbase and a thriving ecosystem.
VS Code has become the editor many developers prefer during recent years, irrespective of their background, language, and technology of choice. Thus, the next logical step is to try and run VS Code anywhere. We have seen, for example, how GitHub integrates it in Codespaces, where you can spawn an instant development environment and tweak the code living in a repository of yours.
Working from home is not the same as remote working. Remote working means working from any location, anywhere in the world, 24 hours a day.
However, the drawback in GitHub Codespaces is the pricing. Currently, the service is in public beta and free to use. But GitHub will be announcing pricing for when Codespaces reaches general availability. Unfortunately, the details we get on the corresponding page are not that encouraging. No free tier, no small instances, and overall inflated prices.
What if you could build your own server, or rent a smaller instance, or even get a bigger one with GPU or TPU acceleration? Moreover, in the story below, we saw how you could isolate your projects and collaborate with your team members easily, using Remote Development.
towardsdatascience.com
But what if you could package VS Code alongside your project dependencies, create a truly flexible environment, fulfill the dream of working from any location, anywhere in the world, whenever you want, or onboarding new team members without any hassle? Let’s see how you can create your own VS Code server!
Learning Rate is a newsletter for those who are curious about the world of AI and MLOps. You’ll hear from me every Friday with updates and thoughts on the latest AI news and articles. Subscribe here!
In this story, we will be using a VM on GCP, but you should easily use any machine or VM provider.
First, start a VM on GCP with at least 2 vCPU cores, 1GB of memory, and 32GB of standard storage. Note that this low-end option is not available on Codespaces. The difference between a VM with this configuration and Codespaces' budget offering is ~4 USD a month (for eight hours a day, five days a week). In Codespaces, you’d pay ~13.5 USD while in GCP ~9.5 USD.
It’s not that big of a difference but using your own VM gives you more flexibility; you can fit it exactly to your needs, scale it up when you need more horsepower, and back down when testing a new idea.
Navigate to Compute Engine -> VM Instances on the sidebarNow click Create Instance to create a new instanceChoose the region closest to you based on gcping.com (any zone is fine)Start an E2 series instance from the General-purpose familyChange the type to custom and set at least 2 vCPU cores and 1GB of RAMChange the Boot Disk to an Ubuntu 20.04 image and set it to 32GBNavigate to Security -> SSH Keys and add your public key there*Click create!
Navigate to Compute Engine -> VM Instances on the sidebar
Now click Create Instance to create a new instance
Choose the region closest to you based on gcping.com (any zone is fine)
Start an E2 series instance from the General-purpose family
Change the type to custom and set at least 2 vCPU cores and 1GB of RAM
Change the Boot Disk to an Ubuntu 20.04 image and set it to 32GB
Navigate to Security -> SSH Keys and add your public key there*
Click create!
* If you don’t know how to create your SSH key see the GCP guide here
Your instance will be ready in a few seconds. Click on the SSH button on the right and connect to the machine and install the VS Code server.
To install a VS Code server, we will use code-server by coder. To install it, run the following command:
curl -fsSL https://code-server.dev/install.sh | sh
Wait a few seconds and then start the server by executing code-server. A VS Code instance will start listening onlocalhost to avoid exposing itself to the world. This is crucial, as someone can completely take over your machine using the VC Code terminal.
So, how can you connect to the server? The simplest method is to use SSH forwarding. First, stop the server and run the following commands to disable the password authentication method and restart the server:
sed -i.bak 's/auth: password/auth: none/' ~/.config/code-server/config.yamlsudo systemctl restart code-server@$USER
Assuming that you have already set a project-wide SSH key, launch your local terminal and run the following command:
ssh -i [path/to/your/private/key] -N -L 8080:127.0.0.1:8080 [user]@<instance-ip>
Finally, launch a terminal and navigate to http://127.0.0.1:8080/. You now have your own VS Code server!
For detailed documentation, visit the code-server docs page on GitHub.
Visual Studio Code is a free, lightweight, and cross-platform code editor, a powerful, distraction-free tool with a dedicated fanbase and a thriving ecosystem.
Running it as a web application enables you to work from any location, anywhere in the world, and using any medium (even your iPad). Moreover, you can package it alongside your projects into siloed containers and create a seamless onboarding process. So, go on and build your own VS Code servers.
My name is Dimitris Poulopoulos, and I’m a machine learning engineer working for Arrikto. I have designed and implemented AI and software solutions for major clients such as the European Commission, Eurostat, IMF, the European Central Bank, OECD, and IKEA.
If you are interested in reading more posts about Machine Learning, Deep Learning, Data Science, and DataOps, follow me on Medium, LinkedIn, or @james2pl on Twitter. Also, visit the resources page on my website, a place for great books and top-rated courses, to start building your own Data Science curriculum!