Help Center/ ModelArts/ Model Development/ Using Notebook Instances Remotely Through VS Code/ Connecting to a Notebook Instance Through VS Code with One Click
Updated on 2026-09-08 GMT+08:00

Connecting to a Notebook Instance Through VS Code with One Click

After remote SSH is enabled for a notebook instance, you can connect to the notebook instance through VS Code with one click.

Prerequisites

  • You have installed the recommended VS Code version and met the constraints. For details, see Recommended VS Code versions and constraints.
  • You have created an account key pair or private key pair on the DEW console and saved the key file to the directories below. For details, see Creating a Key Pair.
    • Windows: C:\Users\{{user}}
    • macOS/Linux: ~
    If you choose I agree to host the private key of the key pair when creating a key pair, you can download the key again by clicking Export Private Key on the Account Key Pairs or Private Key Pairs page. If you do not choose this option, the key will only be available for download once, during creation. Keep your key safe.
    Figure 1 I agree to host the private key of the key pair

  • Remote SSH has been enabled for the notebook instance (select the created account key pair or private key pair), and the instance is in the Running state.

Connecting VS Code to a Notebook Instance

  1. Log in to the ModelArts console and perform the following operations as required:
    • New version: Choose Model Build > Notebook.
    • Old version: Choose Development Space > Notebook.
  2. Click Access Environment in the Operation column of the target notebook instance. In the Access Method dialog box, click the Local tab and click Access on the right of Access VS Code. Choose More > VS Code Access in the Operation column. The dialog box asking you whether to open Visual Studio Code is displayed.
  3. Click Open VS Code.
    • Private key: The name of the private key selected when you enable remote SSH is displayed.
    • VS Code: If VS Code has been installed, a message is displayed indicating that the VS Code client has been installed.
    Figure 2 Opening VS Code

  4. If the ModelArts VS Code extension has not been installed, click Install and Open. If you have installed the extension, remotely connect to your notebook instance.
    Figure 3 Installing the VS Code extension

    The installation takes about 1 to 2 minutes. After the installation is complete, a dialog box is displayed in the lower right corner. Then, click Reload Window and Open.

    This section uses VS Code 1.86 as an example. The Reload Window and Open dialog box may not be displayed when you install other versions of VS Code. In this case, remotely connect to your notebook instance.

    Figure 4 Reload Window and Open

    In the displayed dialog box, select Don't ask again for this extension and click Open.

    Figure 5 Selecting Don't ask again for this extension and clicking Open
  5. Remotely connect to your notebook instance.

    Before the remote connection is executed, the system automatically searches for the key file by name in the following directories: C:\Users\{{user}}\.ssh or downloads (Windows), or /Users/{{user}}/.ss or downloads (Mac/Linux).

    • If the key is found, use it to open a new window and remotely connect to an instance.
      Figure 6 Remotely connecting to a notebook instance
    • If the key file is not found, a dialog box is displayed. Select the correct key as prompted.

      The key file name cannot contain Chinese characters.

      Figure 7 Selecting a key file
      If an incorrect key is selected, a message will be displayed. Then, select the correct key as prompted.
      Figure 8 Selecting the correct key file

    When the information shown in the following figure is displayed, the instance is accessed.

    Figure 9 Connection successful

    The following error message indicates that accessing the instance failed. In this case, close the dialog box and view the output logs in the OUTPUT window. Then, check the FAQs and locate the cause.

    Figure 10 Connection failed

Debugging Code Remotely

  1. On the VS Code page, upload local code to the cloud development environment.
    1. Choose File > OpenFolder, select the path to be opened, and click OK.
      Figure 11 Open Folder
      Figure 12 Selecting a file path

    1. In the displayed directory structure on the left of the IDE, drag the code and files you want to upload to the corresponding folders. Then, the code is uploaded to the cloud development environment.
    2. Open the code file to be debugged in VS Code. Before running the code, click the default Python version in the lower left part and select a version as required.
      Figure 13 Selecting a Python version

  2. Click the execution button to run the code. The code output is shown in the TERMINAL tab.
    • If a training job takes a long time to execute, run the job at the backend using the nohup command. This prevents the disconnection of an SSH session or a network failure from affecting job execution. The following shows an example nohup command:
      nohup your_train_job.sh > output.log 2>&1  &  tail -f  output.log
    • To debug the code, perform the following operations:
      1. Choose Run > Run and Debug on the left.
      2. Select the default Python code file.
      3. Click on the left of the code to set breakpoints.
      4. Debug the code according to the debug procedure which is displayed above the code, and the debug information is displayed on the left of the page.

Reference

If VS Code failed to connect to the notebook instance, see Failures to Access the Development Environment Through VS Code.