Skip to main content
CommandService runs a command inside a container and returns its output, with no ingress, SSH key, or port to configure. Reaching it takes two clients: the Compute API creates the instance, and the response carries a per-instance regional endpoint that serves the command service.
1

Create an instance that stays alive

The container has to be running when the command arrives, so give it a process that waits. sleep is enough.
2

Read the command service endpoint

The create response carries the endpoint in extendedMetadata.commandServiceEndpoint. It is a regional base URL, such as https://zrh2.compute.namespaceapis.com, and the region depends on where the instance landed rather than on where you called the API from. Read it from the response instead of hardcoding it.
There is no need to call WaitInstanceSync first. The command service accepts the call as soon as the container is up, so going straight from CreateInstance to RunCommandSync is the fastest path from nothing to running code.
3

Open a client against that endpoint

The endpoint is a separate service from the Compute API, so it needs its own client carrying the same credential.
4

Run the command

targetContainerName selects which container in the instance runs the command. RunCommandSync blocks and returns the full output, while RunCommand streams it.
stdout and stderr are returned as bytes.

Source

go/exec and typescript/exec in github.com/namespacelabs/examples.
Last modified on October 2, 2026