client.compute. Instance creation is asynchronous: createInstance() allocates an instance and returns its metadata before the instance necessarily reaches the RUNNING state.
The examples on this page use a Compute client:
compute.createInstance()
Create an instance and return its metadata and dashboard URL. Instances are micro-VM backed environments optimized to run containers, deployed with containerd and optionally dockerd and Kubernetes.
Example
Create an instance with a 30-minute deadline:- Linux
- macOS
- Windows
- Linux on Apple Silicon
API reference
Arguments and options
createInstance() accepts a CreateInstanceRequest. Common fields include:
CPU, memory, architecture, operating system, and optional platform selectors for the instance.
When Namespace should release the instance. Workspace policy can shorten the requested deadline.
Ordered placement selectors such as
site:iad2, continent:us, or any. When omitted, Namespace selects capacity for the workload.Containers to start during instance creation. Containers are supported on Linux instances.
CreateInstanceRequest API reference.
Cancellation, timeout, and header options. See Shared call options.
Return value
createInstance() returns a DescribeInstanceResponse. Use metadata.instanceId for subsequent Compute API calls and instanceUrl to open the instance in the Namespace dashboard.
Extended metadata is returned at creation time and by describeInstance(), but not by listInstances(). See the complete DescribeInstanceResponse API reference.
If the workspace is out of resources, the call fails with ResourceExhausted. An invalid argument, such as a non-existing region, fails with InvalidArgument.
More examples
Start a container during creation
Linux instances can start containers as part of the creation request:Select instance placement
Use ordered placement selectors to constrain where Namespace creates the instance. Namespace tries each selector in order:compute.waitInstance()
Wait until an instance reaches the RUNNING state. waitInstanceSync() resolves once the instance is running. waitInstance() is the server-streaming variant: it emits a response for each state progression and the server closes the stream when the instance is running.
Example
Wait for the instance with a 10-minute timeout:instanceId is the value read from metadata.instanceId on the createInstance() response.
Use the streaming method when you need intermediate state updates:
API reference
Arguments and options
Wait for a specific container by the name given in
ContainerRequest.name. When both containerId and containerName are set, containerName takes precedence.Cancellation, timeout, and header options. See Shared call options.
Return value
EachWaitInstanceResponse carries metadata, the current InstanceMetadata, and containerStatus. If the instance is already running when the call is made, a single response is returned and the stream closes immediately.
If the instance does not exist, the call fails with NotFound. If instance creation is unsuccessful, the call fails with Internal; read metadata.status from the last response for the detailed status.
compute.startContainers()
Add containers to a running instance. This is the runtime counterpart to the containers field on createInstance().
Example
API reference
Arguments and options
The additional containers to start.
ContainerRequest takes the same shape as at creation time, including name, imageRef or knownImageId, entrypoint, args, envVars, exportPorts, volumes, and privileged. See the complete ContainerRequest API reference.Cancellation, timeout, and header options. See Shared call options.
Return value
Returns aStartContainersResponse with containers, the allocated containers in the same order as the request. Each AllocatedContainer carries the Namespace-allocated id, the name you gave it, and any exportedPort entries with their public ingress URLs.
If the instance does not exist, the call fails with NotFound.
Namespace-managed containers are treated as critical: if one fails, through an early exit or an out-of-memory kill, the instance fails with it. Containers started through the containerd or Docker APIs yourself are not managed this way.
compute.describeInstance()
Fetch the metadata of a previously created instance, including the extended metadata that listInstances() does not return.
Example
API reference
Arguments and options
Cancellation, timeout, and header options. See Shared call options.
Return value
Returns aDescribeInstanceResponse with instanceUrl, metadata, extendedMetadata, the image registry, allocated containers, attachments, shutdownReasons, and workloadPermissions.
If the instance does not exist, the call fails with NotFound.
compute.listInstances()
Return one page of instances in the workspace. By default the response only includes instances in the PENDING, CREATING, and RUNNING states.
Example
API reference
Arguments and options
The maximum number of entries to return. The service returns no more than
maxEntries, and may return fewer.The
paginationCursor from a previous response. Continues reading results with the arguments of the original call.Cancellation, timeout, and header options. See Shared call options.
Return value
Returns aListInstancesResponse with instances, a list of InstanceMetadata, and a paginationCursor for the next page. Call describeInstance() when you need extended metadata for one of the listed instances.
compute.extendInstance()
Extend the lifetime of an instance. Use extendBy to add to the current deadline, ensureMinimum to guarantee a remaining runtime, or newDeadline to set an absolute deadline.
Example
API reference
Arguments and options
Cancellation, timeout, and header options. See Shared call options.
Return value
Returns anExtendInstanceResponse with the resulting newDeadline. Workspace policy can shorten the requested deadline.
If the instance does not exist, the call fails with NotFound.
compute.suspendInstance()
Suspend a running instance. Execution stops and RAM and disks are snapshotted so the instance can be restored without restarting it.
Example
API reference
Arguments and options
Cancellation, timeout, and header options. See Shared call options.
Return value
Returns an empty response. If the instance does not exist, the call fails withNotFound.
compute.wakeInstance()
Wake a suspended instance. The call is a no-op when the instance is already running.
Example
API reference
Arguments and options
Cancellation, timeout, and header options. See Shared call options.
Return value
Returns an empty response. If the instance does not exist, the call fails withNotFound. If the instance is neither suspended nor running, the call fails with FailedPrecondition.
compute.destroyInstance()
Destroy an instance and release its resources.
Example
API reference
Arguments and options
Cancellation, timeout, and header options. See Shared call options.
Return value
Returns an empty response. If the instance does not exist, the call fails withNotFound.
compute.releaseUniqueTag()
Release the instance ID currently associated with a unique tag.
Example
API reference
Arguments and options
Cancellation, timeout, and header options. See Shared call options.
Return value
Returns aReleaseUniqueTagResponse whose instanceId is the instance that was released from the tag, or an empty string when no instance was associated.
If the unique tag does not exist, the call fails with NotFound.
Unique tags are assigned through an experimental instance-creation capability. Reach out to the Namespace team before relying on them.Tags are unique per region, so this call must reach the Compute endpoint for the region that holds the tag. Inside an instance,
NSC_ENDPOINT points at the endpoint for the current region.Shared call options
All methods on this page accept ConnectCallOptions as their second argument.
Related documentation
Compute Client
Configure authentication, region, and transport.
Machine shapes
Supported CPU, memory, and platform configurations.
Compute platform
Platforms, storage, networking, and instance access.