Skip to content

Visual Studio Code

VS Code can connect to a compute node on the cluster via SSH, giving you a full remote development environment with terminal, file browser, and extensions.

Looking for a simpler setup?

If you don't want to install anything locally, check out code-server: a full VS Code environment that runs entirely in your browser.

Do not run VS Code on login nodes

VS Code runs background processes that consume significant CPU and memory. Running it on a login node will degrade the cluster for all users and your session may be terminated. Always connect to a compute node through a SLURM allocation.

Prerequisites

Step 1: Request a compute node

Submit a job that starts a private SSH server on a compute node:

vscode.slurm
#!/bin/bash
#SBATCH --qos=regular
#SBATCH --job-name=vscode
#SBATCH --nodes=1
#SBATCH --ntasks=1
#SBATCH --cpus-per-task=4
#SBATCH --mem=16G
#SBATCH --time=08:00:00
#SBATCH --output=/scratch/%u/vscode-%j.out
#SBATCH --error=/scratch/%u/vscode-%j.err

module load DIPC-Utils/0.0.2

ssh-server-start.sh

Atlas clusters

On Atlas FDR and Atlas EDR, add the -a flag: ssh-server-start.sh -a

Submit with sbatch vscode.slurm, then check the output file once the job starts:

cat /scratch/$USER/vscode-<JOBID>.out

You will see something like:

==============================================================
Custom SSH Server Started
==============================================================
Hostname: hyperion-260
Port: 11332
==============================================================
To securely connect to the custom SSH server, set up SSH tunneling:
1. Run the following command on your local machine:

   ssh -L <local-port>:hyperion-260:11332 <username>@hyperion.sw.ehu.es -N

2. Connect your SSH client to 'localhost:<local-port>'.
==============================================================

Note the hostname and port: you need them for the next step.

Step 2: Create an SSH tunnel

On your local machine, open a terminal and create a tunnel using the hostname and port from the job output:

ssh -L 2222:COMPUTE_NODE:PORT USERNAME@hyperion.sw.ehu.es -N

Replace COMPUTE_NODE, PORT, and USERNAME with your actual values. For example:

ssh -L 2222:hyperion-260:11332 <username>@hyperion.sw.ehu.es -N

This maps your local port 2222 to the SSH server running on the compute node. If port 2222 is already in use locally, pick another one (e.g., 12222).

Info

You need to recreate this tunnel every time the SLURM job restarts (new node, new port).

Step 3: Configure and connect VS Code

Add an entry to ~/.ssh/config on your local machine:

~/.ssh/config
Host hyperion-tunnel
  HostName localhost
  Port 2222
  User USERNAME

Replace USERNAME with your cluster username, and Port with the local port you chose in step 2.

Then in VS Code:

  1. Open the Remote Explorer panel. The hyperion-tunnel entry should appear.

    VS Code Remote Explorer

  2. Click to connect. VS Code will install its server component on the compute node (first time only).

  3. Browse to your project directory on the cluster and start working.

Using Jupyter notebooks

VS Code can run Jupyter notebooks directly on the compute node.

  1. Install the Jupyter and Python extensions on the remote VS Code instance (they install on the cluster, not locally).

  2. Open a terminal inside VS Code and load the Miniforge3 module:

    module load Miniforge3
    
  3. Open your .ipynb file. If VS Code asks you to select a kernel, click Select Another Kernel:

    Select kernel

  4. Choose Python Environments, then select the base conda environment (the one provided by module load Miniforge3):

    Select Python environment

    Warning

    Do not select the "recommended" kernel, as it may point to the system Python which lacks scientific packages.

  5. Your notebook should now execute on the compute node:

    Running notebook

Julia notebooks

  1. Install the Jupyter and Julia extensions on the remote instance.

  2. Load the Julia module in the VS Code terminal:

    module load Julia
    
  3. If the Julia extension cannot find the binary, set julia.executablePath in the extension settings:

    Julia executable path

  4. If you use a custom Julia environment (created with Pkg), activate it from the Julia extension panel:

    Julia environment

Troubleshooting

VS Code cannot connect after the tunnel is up

Verify that the SLURM job is still running (squeue -u $USER). If the job ended, the SSH server is gone and you need to submit a new one.

Port already in use locally

Change the local port in both the ssh -L command and your ~/.ssh/config.

Modules not available in VS Code terminal

VS Code opens a non-login shell, so .bash_profile is not sourced. Add your module load commands to ~/.bashrc, or run them manually in the VS Code terminal each session.

ssh-server-start.sh fails

As a fallback, request an interactive allocation and tunnel to the node's standard SSH port (22):

srun --nodes=1 --ntasks=1 --cpus-per-task=4 --mem=16G --qos=regular --time=8:00:00 --pty bash

Then create the tunnel to port 22 of the allocated node:

ssh -L 2222:COMPUTE_NODE:22 USERNAME@hyperion.sw.ehu.es -N

See also

  • code-server (VS Code in browser)


    Run VS Code in the browser without any local installation.

    code-server guide

  • Jupyter Notebook


    Run Jupyter notebooks on compute nodes via SSH tunnel.

    Jupyter guide

  • VNC sessions


    Remote desktop for GUI applications.

    VNC guide