Skip to content

Visual Studio Code (VS Code)

Prerequisites

To work through these guides you must:

  • Be a member of a project in the BriCS portal
  • Have followed the instructions in Getting Started to set up SSH login and create a valid SSH certificate for authenticating to BriCS facilities (using the clifton command line tool)

Additionally, a GitHub account is required to follow the instructions to connect to VS Code running on a compute node.

Start an interactive VS Code session on a compute node

This guide outlines a procedure for starting a VS Code remote tunnel that allows a VS Code session on your computer (via a web browser or VS Code desktop application) to use a compute node interactively.

Install VS Code CLI

Connect to a login node over SSH, following the instructions in the guide on logging in.

Download the VS Code standalone CLI, extracting the archive and placing the binary in a suitable location, e.g.

curl --location --output vscode_cli.tar.gz "https://update.code.visualstudio.com/latest/cli-linux-arm64/stable"
mkdir -p ~/opt/vscode_cli_arm64
tar --directory ~/opt/vscode_cli_arm64 --extract --verbose --file vscode_cli.tar.gz
curl --location --output vscode_cli.tar.gz "https://update.code.visualstudio.com/latest/cli-linux-x64/stable"
mkdir -p ~/opt/vscode_cli_x64
tar --directory ~/opt/vscode_cli_x64 --extract --verbose --file vscode_cli.tar.gz

Check the version of the CLI installed for the system you are using:

$ ~/opt/vscode_cli_arm64/code --version
code 1.143.1 (commit e646868227c3e3a9e3f24277c8c7220be42c0be7)
$ ~/opt/vscode_cli_x64/code --version
code 1.143.1 (commit e646868227c3e3a9e3f24277c8c7220be42c0be7)
Specific versions of VS Code

To download a specific version of the VS Code CLI, replace latest in the download URL with the version number, e.g. https://update.code.visualstudio.com/1.143.1/cli-linux-x64/stable. Keep the architecture part of the URL (cli-linux-arm64 or cli-linux-x64) that matches the system you are using.

Submit a job to start a code tunnel

From the login node, submit a job which runs code tunnel on a compute node. Use the submission script for the system and type of node you want, and submit it with sbatch:

Download the submission script: submit_example_vscode_code_tunnel_isambard_ai_gpu.sh

submit_example_vscode_code_tunnel_isambard_ai_gpu.sh
#!/bin/bash
#SBATCH --job-name=code_tunnel
#SBATCH --nodes=1
#SBATCH --gpus=1 # this also allocates 72 CPU cores and 115GB memory
#SBATCH --time=1:00:00
#SBATCH --output=code_tunnel_%j.out

# Start named VS Code tunnel for remote connection to compute node
~/opt/vscode_cli_arm64/code tunnel --name "gpu_tunnel"
$ sbatch submit_example_vscode_code_tunnel_isambard_ai_gpu.sh
Submitted batch job 16050

Download the submission script: submit_example_vscode_code_tunnel_isambard_3_grace_cpu.sh

submit_example_vscode_code_tunnel_isambard_3_grace_cpu.sh
#!/bin/bash
#SBATCH --job-name=code_tunnel
#SBATCH --nodes=1
#SBATCH --cpus-per-task=4
#SBATCH --time=1:00:00
#SBATCH --output=code_tunnel_%j.out

# Start named VS Code tunnel for remote connection to compute node
~/opt/vscode_cli_arm64/code tunnel --name "cpu_tunnel"
$ sbatch submit_example_vscode_code_tunnel_isambard_3_grace_cpu.sh
Submitted batch job 16050

Download the submission script: submit_example_vscode_code_tunnel_isambard_3_macs_cpu.sh

submit_example_vscode_code_tunnel_isambard_3_macs_cpu.sh
#!/bin/bash
#SBATCH --job-name=code_tunnel
#SBATCH --nodes=1
#SBATCH --cpus-per-task=4
#SBATCH --time=1:00:00
#SBATCH --output=code_tunnel_%j.out

# Start named VS Code tunnel for remote connection to compute node
~/opt/vscode_cli_x64/code tunnel --name "cpu_tunnel"
$ sbatch submit_example_vscode_code_tunnel_isambard_3_macs_cpu.sh
Submitted batch job 16050

Download the submission script: submit_example_vscode_code_tunnel_bluecrystal_5_cpu.sh

submit_example_vscode_code_tunnel_bluecrystal_5_cpu.sh
#!/bin/bash
#SBATCH --job-name=code_tunnel
#SBATCH --nodes=1
#SBATCH --cpus-per-task=4
#SBATCH --time=1:00:00
#SBATCH --output=code_tunnel_%j.out

# Start named VS Code tunnel for remote connection to compute node
~/opt/vscode_cli_x64/code tunnel --name "cpu_tunnel"
$ sbatch submit_example_vscode_code_tunnel_bluecrystal_5_cpu.sh
Submitted batch job 16050

Download the submission script: submit_example_vscode_code_tunnel_bluecrystal_5_gpu.sh

submit_example_vscode_code_tunnel_bluecrystal_5_gpu.sh
#!/bin/bash
#SBATCH --job-name=code_tunnel
#SBATCH --nodes=1
#SBATCH --partition=gpu
#SBATCH --gpus=1
#SBATCH --time=1:00:00
#SBATCH --output=code_tunnel_%j.out

# Start named VS Code tunnel for remote connection to compute node
~/opt/vscode_cli_x64/code tunnel --name "gpu_tunnel"

$ sbatch submit_example_vscode_code_tunnel_bluecrystal_5_gpu.sh Submitted batch job 16050 ```

Once the job starts running, examine the output file (named code_tunnel_<JOB_ID>.out), e.g.

*
* Visual Studio Code Server
*
* By using the software, you agree to
* the Visual Studio Code Server License Terms (https://aka.ms/vscode-server-license) and
* the Microsoft Privacy Statement (https://privacy.microsoft.com/en-US/privacystatement).
*
[Timestamp] info Using GitHub for authentication, run `code tunnel user login --provider <provider>` option to change this.
To grant access to the server, please log into https://github.com/login/device and use code ABC1-DEF2

Open this link in your browser https://vscode.dev/tunnel/{your-tunnel-name}/{path-to-your-home-directory}

The output shows that your remote VS Code server is up and running and using GitHub for authentication (you do not need to change the login provider).

Now go to https://github.com/login/device and enter the code given ("ABC1-DEF2" in the example above) to authenticate server access.

Connect VS Code in a web browser

At this point you can access the VS Code server on the compute node using a web browser, following the instructions in the job output file.

Open the vscode.dev link shown in the job output file (code_tunnel_<JOB_ID>.out) in a web browser and, when prompted, select "GitHub" as the type of account to connect.

Screenshot of VS Code web prompting for the type of account to connect to the tunnel

After you have authenticated with your GitHub account, you can work in VS Code in the browser.

Screenshot of VS Code web connected to the tunnel

Connect VS Code desktop application

Additional prerequisites for desktop VS Code

To connect a desktop VS Code application (not browser-based) running on your computer to a remote VS Code tunnel on a compute node, make sure that you have the latest version of VS Code installed with the Remote - Tunnels extension. You can install this from the Extensions view (Ctrl+Shift+X, or Cmd+Shift+X on Mac) by searching for "Remote - Tunnels".

We also recommend installing the Remote Explorer extension, which provides the Remote Explorer view in VS Code where remote connections can be managed.

You can also set up a desktop VS Code application to access the compute node.

We recommend you first test connecting via a browser before trying desktop access.

To access your VS Code server on a compute node from the VS Code desktop application, make sure your VS Code installation meets the prerequisites above. Then start a VS Code tunnel job, noting the tunnel name set in your submission script, e.g. "gpu_tunnel" or "cpu_tunnel" in the examples above. Once the vscode.dev link has been generated, follow these steps in your VS Code desktop application:

  1. Open Command Palette: In VS Code, press Ctrl+Shift+P (Cmd+Shift+P on Mac) to open the Command Palette.

  2. Connect to tunnel: Type "Remote-Tunnels: Connect to Tunnel..." and select GitHub from the dropdown box.

    Screenshot of VS Code desktop connecting to tunnel

  3. Authenticate: If prompted, authenticate using your GitHub account for the tunnel.

    Screenshot of VS Code desktop authenticating with GitHub

    This step ensures a secure connection to your VS Code server running on the worker node.

  4. Enter tunnel details: Select your tunnel name from the list to connect. In the screenshot below, the tunnel name is "i-ai_compute".

    Screenshot of VS Code desktop connected

  5. Establish connection: VS Code should now connect to the remote environment via the tunnel, providing access to the remote file system and integrated terminal on the compute node.

Use VS Code empty profile for debugging issues

If you have problems connecting, try using an empty profile, which starts VS Code without any extensions.

Happy coding!

Stop the interactive session

Once you have finished working interactively with VS Code on the compute node, cancel the job to release resources for other users.

Connect to a login node over SSH, following the instructions in the guide on logging in.

Cancel the job using the job ID returned by the sbatch command used to submit the code tunnel job, replacing <JOB_ID> with that job ID:

scancel ```

Finding the job ID

To find the job IDs of your currently scheduled jobs, use squeue, e.g.

$ squeue --me JOBID USER PARTITION NAME ST TIME_LIMIT TIME TIME_LEFT NODES NODELIST(REASON) 17886 user.project workq code_tunnel PD 1:00:00 0:00 1:00:00 1 (Priority) ```