What's an Instance?
If your goal is a workspace (VSCode/Cursor, tmux agents, easy preview URLs), start with Devboxes: Getting started.
Instances are the underlying VM primitive for power users who want direct control over VMs and snapshots.
Every virtual machine (VM) running in Morph Cloud is an instance. Each instance runs from a saved snapshot. This guide covers the basic lifecycle operations for instances, including starting, stopping, and saving them.
Start an Instance
To launch a new instance, you need a Snapshot ID. The instance will be created based on the specified snapshot.
- Python
- TypeScript
- CLI
from morphcloud.api import MorphCloudClient
client = MorphCloudClient()
snapshot_id = "snapshot_abc123" # Replace with a valid snapshot ID
instance = client.instances.start(snapshot_id=snapshot_id)
print(f"Instance started with ID: {instance.id}")
import { MorphCloudClient } from 'morphcloud';
const client = new MorphCloudClient();
async function startInstance() {
const snapshot_id = "snapshot_abc123"; // Replace with a valid snapshot ID
const instance = await client.instances.start({ snapshot_id: snapshot_id });
console.log(`Instance started with ID: ${instance.id}`);
}
startInstance();
# Start an instance from a snapshot
morphcloud instance start snapshot_abc123
Get Instance Details
To get detailed information about a specific instance, use its ID.
- Python
- TypeScript
- CLI
from morphcloud.api import MorphCloudClient
client = MorphCloudClient()
instance_id = "morphvm_abc123" # Replace with a valid instance ID
instance = client.instances.get(instance_id=instance_id)
print(f"Instance ID: {instance.id}, Status: {instance.status}, Networking: {instance.networking}")
import { MorphCloudClient } from 'morphcloud';
const client = new MorphCloudClient();
async function getInstanceDetails() {
const instance_id = "morphvm_abc123"; // Replace with a valid instance ID
const instance = await client.instances.get({ instance_id: instance_id });
console.log(`Instance ID: ${instance.id}, Status: ${instance.status}, Networking: ${JSON.stringify(instance.networking)}`);
}
getInstanceDetails();
# Get instance details
morphcloud instance get morphvm_abc123
List Instances
You can retrieve a list of all instances in your Morph Cloud account.
- Python
- TypeScript
- CLI
from morphcloud.api import MorphCloudClient
client = MorphCloudClient()
# List all instances
instances = client.instances.list()
for instance in instances:
print(f"ID: {instance.id}, Status: {instance.status}, Snapshot ID: {instance.refs.snapshot_id}")
import { MorphCloudClient } from 'morphcloud';
const client = new MorphCloudClient();
async function listInstances() {
// List all instances
const instances = await client.instances.list();
instances.forEach(instance => {
console.log(`ID: ${instance.id}, Status: ${instance.status}, Snapshot ID: ${instance.refs.snapshot_id}`);
});
}
listInstances();
# List all instances
morphcloud instance list
Save an Instance (Create Snapshot)
You can create a snapshot from a running instance, capturing its current state for future use or as a backup.
- Python
- TypeScript
- CLI
from morphcloud.api import MorphCloudClient
client = MorphCloudClient()
instance_id = "morphvm_abc123" # Replace with a valid instance ID
instance = client.instances.get(instance_id=instance_id)
new_snapshot = instance.snapshot()
print(f"Snapshot created from instance '{instance_id}' with ID: {new_snapshot.id}")
import { MorphCloudClient } from 'morphcloud';
const client = new MorphCloudClient();
async function createSnapshotFromInstance() {
const instance_id = "morphvm_abc123"; // Replace with a valid instance ID
const instance = await client.instances.get({ instance_id: instance_id });
const newSnapshot = await instance.snapshot();
console.log(`Snapshot created from instance '${instance_id}' with ID: ${newSnapshot.id}`);
}
createSnapshotFromInstance();
# Create a snapshot from an instance
morphcloud instance snapshot morphvm_abc123
Stop an Instance
Stopping an instance terminates the virtual machine and releases the resources.
- Python
- TypeScript
- CLI
from morphcloud.api import MorphCloudClient
client = MorphCloudClient()
instance_id = "morphvm_abc123" # Replace with a valid instance ID
instance = client.instances.get(instance_id=instance_id)
instance.stop()
print(f"Instance '{instance_id}' stopped.")
import { MorphCloudClient } from 'morphcloud';
const client = new MorphCloudClient();
async function stopInstance() {
const instance_id = "morphvm_abc123"; // Replace with a valid instance ID
const instance = await client.instances.get({ instance_id: instance_id });
await instance.stop();
console.log(`Instance '${instance_id}' stopped.`);
}
stopInstance();
# Stop an instance
morphcloud instance stop morphvm_abc123