Skip to main content

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:

  1. Make sure you've installed the SDK
  2. Set up your API key

Create and Run a Hello World Instance

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")

Next Steps

Now that you've created your first Morph Cloud instance, you can: