Run SDK Code

After saving your code sample and adding control logic with Viam’s SDKs, run your program to control your Viam-connected robot.


You must authenticate yourself to the robot using the robot’s location secret. However, the app hides the robot location secret from the sample by default for your security.

To copy the robot location secret, select Include Secret on the Code sample tab of your robot’s page on the Viam app. Paste it into your environment variables or directly into your code.

You must also include the robot’s remote address, like, as an external or public address to connect to your robot. The code sample includes this address at default. You can find it at the top of the robot’s Control tab.

Run Code Remotely

Most of the time, as long as both you and your robot are connected to the internet, you will want to run code to control your robot remotely. The advantage of this method is that your robot and your computer do not have to be connected to the same WAN/LAN to issue control commands. You can remotely control your robot with any application you implement from anywhere in the world. For example, you can run code on your personal computer, creating a client session, where the code running on that computer sends instructions to your robot’s viam-server instance over the internet.

After editing your code to include your robot’s authentication credentials, run a command to execute the program in the terminal of a machine with the appropriate programming language and Viam SDK installed:

python3 ~/myCode/
go run ~/myCode/

For an example, see this execution demo.

For information on running C++ code see the instructions on GitHub.

flutter run <DART_FILE>

This is useful because as long as that computer is able to establish a network connection with the robot’s computer, your control logic will be executed on the robot.

Run Code On-Robot

In case you run PID control loops or your robots have intermittent network connectivity, you can ensure this does not interfere with the code’s execution, by running the control code on the same board that is running viam-server.

When connecting to a robot using the connection code from the code sample tab, a client session automatically uses the most efficient route to connect to your robot, which means the favored route for commands will be over localhost.

Run code automatically

If you want to run your code automatically when your robot boots, you can configure Viam to run your code as a process.

To be able to run your code from your board, you need to install the relevant SDK as well as other required dependencies:

  1. ssh into your board and install pip:

    sudo apt install python3-pip
  2. Create a folder robot inside your home directory:

    mkdir robot
  3. Then install the Viam Python SDK and the VLC module into that folder:

    pip3 install --target=robot viam-sdk <other-required-dependencies>
  4. Add your code to your new folder:

    scp user@host.local:/home/myboard/robot/

Now navigate to the Config tab of your robot’s page in the Viam app. Click on the Processes subtab and navigate to the Create process menu.

Enter main as the process name and click Create process.

In the new process panel, enter python3 as the executable, as the argument, and the working directory of your board Pi as /home/myboard/robot. Click on Add argument.

Click Save config in the bottom left corner of the screen.

Now your robot will start its code automatically once booted.

Have questions, or want to meet other people working on robots? Join our Community Discord.