Hello World Example
This guide will walk you through creating your first Morph Cloud instance and running a simple "Hello World" command.
Prerequisites
Before starting:
- Make sure you've installed the SDK
- Set up your API key
Create and Run a Hello World Instance
- Python
- TypeScript
- CLI
from morphcloud.api import MorphCloudClient
# Initialize client
client = MorphCloudClient()
# 1. Create a new snapshot (or list existing ones)
new_snapshot = client.snapshots.create(
vcpus=1,
memory=1024, # MB
disk_size=10000 # MB
)
print(f"Created snapshot: {new_snapshot.id}")
# 2. Start an instance from the snapshot
instance = client.instances.start(snapshot_id=new_snapshot.id)
print(f"Started instance: {instance.id}")
# 3. Run a hello world command
result = instance.exec(command="echo 'Hello, Morph Cloud!'")
print(f"Command output: {result.stdout}")
# 4. Stop the instance when done
instance.stop()
print("Instance stopped")
import { MorphCloudClient } from 'morphcloud';
async function helloWorld() {
// Initialize client
const client = new MorphCloudClient();
// 1. Create a new snapshot (or list existing ones)
const newSnapshot = await client.snapshots.create({
vcpus: 1,
memory: 1024, // MB
diskSize: 10000 // MB
});
console.log(`Created snapshot: ${newSnapshot.id}`);
// 2. Start an instance from the snapshot
const instance = await client.instances.start({ snapshotId: newSnapshot.id });
console.log(`Started instance: ${instance.id}`);
// 3. Run a hello world command
const result = await instance.exec("echo 'Hello, Morph Cloud!'");
console.log(`Command output: ${result.stdout}`);
// 4. Stop the instance when done
await instance.stop();
console.log("Instance stopped");
}
helloWorld().catch(console.error);
# 1. Create a new snapshot
SNAPSHOT_ID=$(morphcloud snapshot create --vcpus 1 --memory 1024 --disk-size 10000 | grep -o 'snapshot_[a-zA-Z0-9]*')
# 2. Start an instance from the snapshot
INSTANCE_ID=$(morphcloud instance start $SNAPSHOT_ID | grep -o 'morphvm_[a-zA-Z0-9]*')
# 3. Run a hello world command
morphcloud instance exec $INSTANCE_ID echo "Hello, Morph Cloud!"
# 4. Stop the instance when done
morphcloud instance stop $INSTANCE_ID
Next Steps
Now that you've created your first Morph Cloud instance, you can:
- Learn about instance lifecycle management
- Explore command execution
- Set up SSH access to your instances
- Configure HTTP services