Skip to main content

Shares & Custom Domains

Shares expose ports from a running VM to the public internet. Use shares to preview web applications, expose APIs, or share running services.

Creating a share

Expose a port from your current session:

from instavm import InstaVM

client = InstaVM('your_api_key')

share = client.shares.create(
port=8080,
is_public=True
)

print(f"Public URL: {share.get('public_url')}")

Public vs private shares

  • Public shares are accessible by anyone with the URL.
  • Private shares require an access token to reach.
# Public share
share = client.shares.create(port=3000, is_public=True)

# Private share
share = client.shares.create(port=3000, is_public=False)
print(f"Access token: {share.get('access_token')}")

Sharing from a specific VM

Share a port from a VM you created via the VM manager:

share = client.shares.create(
vm_id="vm_abc123",
port=3000,
is_public=True
)

Updating a share

Toggle visibility or revoke access:

# Make a private share public
client.shares.update(share_id="share_def456", is_public=True)

# Revoke a share
client.shares.update(share_id="share_def456", revoke=True)

Custom domains

Point your own domain at a shared port for production-ready URLs.

Create a 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_def456"}'

Verify DNS

Add a CNAME record pointing your domain to the provided target, then verify:

curl -X POST https://api.instavm.io/v1/custom-domains/{domain_id}/verify \
-H "Authorization: Bearer sk_instavm_..."

List and delete

# List all custom domains
curl https://api.instavm.io/v1/custom-domains \
-H "Authorization: Bearer sk_instavm_..."

# Delete a custom domain
curl -X DELETE https://api.instavm.io/v1/custom-domains/{domain_id} \
-H "Authorization: Bearer sk_instavm_..."

Use case: preview a web app

from instavm import InstaVM

with InstaVM('your_api_key') as vm:
# Start a Flask server
vm.execute("""
import subprocess, sys
subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'flask'])
""")

vm.execute_async("""
from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello():
return '<h1>Hello from InstaVM</h1>'

app.run(host='0.0.0.0', port=8080)
""")

# Share the port
share = vm.shares.create(port=8080, is_public=True)
print(f"Preview: {share.get('public_url')}")

Next steps