Run a command inside container using SDK

I am trying to run a .sh script (that sends an image to our database from the device) through our companies admin dashboard. Is there a way to use the SDK to push a bash exec command to a specific container?

For clarity, this is what I am trying to do:

  1. Our admin logs into our dashboard
  2. Our admin want to retrieve an image from the device
  3. Admin clicks ‘Retrieve Image’
  4. Our API connects to Balena SDK and runs ‘./’
  5. The response from ./ script is returned to the admin dashboard


Hi @hunter, I don’t think it’s possible to use the SDK to push commands to a device. You could somewhat hack the CLI to achieve part of it though, would that work for you?

Here is what I would do. You can pipe commands to the SSH CLI command: echo "uptime; exit;" | balena ssh <DEVICE_UUID>. This will run uptime on the device’s hostOS, send the result back and exit. If you instead pipe the contents of a script you could run a script that uses balenaEngine to connect to the container from the hostOS and then run a command there. Let me exemplify.

You would need to run:

cat | balena ssh <DEVICE_UUID>

And your would look like this:

balena exec -it <CONTAINER_ID> sh -c "uptime; exit;"

This will run uptime in container <CONTAINER_ID> which is running on device <DEVICE_UUID>.