Deploy a Web App
Spin up a VM, install dependencies, run a web server, and expose it to the internet using InstaVM shares.
Flask example
from instavm import InstaVM
vm = InstaVM("your_api_key")
# Install Flask
vm.execute("""
import subprocess, sys
subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'flask'])
print("Flask installed")
""")
# Start the server (async so it doesn't block)
vm.execute_async("""
from flask import Flask, jsonify
app = Flask(__name__)
@app.route('/')
def index():
return '<h1>Hello from InstaVM</h1>'
@app.route('/api/status')
def status():
return jsonify({"status": "running"})
app.run(host='0.0.0.0', port=8080)
""")
# Expose port 8080
share = vm.shares.create(port=8080, is_public=True)
print(f"App live at: {share.get('public_url')}")
Next.js example
from instavm import InstaVM
vm = InstaVM("your_api_key", memory_mb=2048)
# Set up Node.js and create a Next.js app
vm.execute("""
import subprocess
subprocess.run(['npx', 'create-next-app@latest', 'myapp', '--yes'], check=True)
print("Next.js app created")
""", timeout=120)
# Start dev server
vm.execute_async("""
import subprocess, os
os.chdir('/app/myapp')
subprocess.run(['npm', 'run', 'dev', '--', '-p', '3000'])
""")
share = vm.shares.create(port=3000, is_public=True)
print(f"Next.js app: {share.get('public_url')}")
Upload your own code
Deploy existing code by uploading it to the VM:
from instavm import InstaVM
vm = InstaVM("your_api_key")
# Upload your app
vm.upload_file("./app.py", remote_path="/app/app.py")
vm.upload_file("./requirements.txt", remote_path="/app/requirements.txt")
# Install dependencies and start
vm.execute("""
import subprocess, sys
subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-r', '/app/requirements.txt'])
print("Dependencies installed")
""")
vm.execute_async("exec(open('/app/app.py').read())")
share = vm.shares.create(port=8080, is_public=True)
print(f"Your app: {share.get('public_url')}")
Custom domains
Point your own domain at the shared port:
# Create custom domain
curl -X POST https://api.instavm.io/v1/custom-domains \
-H "Authorization: Bearer sk_instavm_..." \
-H "Content-Type: application/json" \
-d '{"domain": "app.example.com", "share_id": "share_..."}'
# Add CNAME record: app.example.com → <provided target>
# Then verify:
curl -X POST https://api.instavm.io/v1/custom-domains/{id}/verify \
-H "Authorization: Bearer sk_instavm_..."
VM lifecycle
For long-running apps, create a VM with an explicit lifetime:
client = InstaVM("your_api_key")
vm = client.vms.create(
wait=True,
vm_lifetime_seconds=86400, # 24 hours
memory_mb=2048,
vcpu_count=2
)
To persist the environment, snapshot it before it expires:
client.vms.snapshot(vm_id=vm['vm_id'], name="my-app-snapshot", wait=True)
Next steps
- Shares & Custom Domains -- how shares work
- Snapshots -- persisting VM state
- File Operations -- uploading project files