Skip to main content

Official Python SDK for MIOSA — the AI cloud platform for sandboxes, desktop computers, deployments, managed databases, S3 storage, and volumes.

Project description

miosa (Python)

Official Python SDK for MIOSA — the AI cloud platform for sandboxes, computers, deployments, and managed data.

PyPI version Python versions License: MIT Docs

Install

pip install miosa
# or
uv add miosa
# or
poetry add miosa

Requires Python 3.9+. Dependencies: httpx, pydantic v2.

Quickstart

from miosa import Miosa

miosa = Miosa(api_key="msk_live_...")

# Boot a computer, run a command, expose a preview
computer = miosa.computers.create(
    name="my-build",
    template_type="miosa-sandbox",
    size="small",
)
computer.start()
computer.wait(status="running")

result = computer.exec.run("python --version")
print(result.stdout)   # Python 3.12.x

computer.files.write_file("/workspace/hello.py", "print('hello from miosa')")
out = computer.exec.run("python /workspace/hello.py")
print(out.stdout)      # hello from miosa

print(computer.preview_url(8000, "/"))
# https://8000-<slug>.sandbox.<tenant-domain>/

computer.destroy()

What's included

Resource Description
miosa.computers Firecracker microVMs — full lifecycle, exec, files, services
miosa.sandboxes Lightweight code-execution VMs via the /sandboxes route
miosa.deployments Versioned production releases with rollback
miosa.databases Managed Postgres / Redis lifecycle
miosa.storage S3-compatible object storage
miosa.volumes Persistent block storage
miosa.api_keys Programmatic API key management
miosa.usage Usage reports per workspace, per external tenant
miosa.settings Workspace config, branding, BYOK provider keys
miosa.webhooks Outgoing tenant webhooks — CRUD, test, delivery history
miosa.open_computers BYOC host management — register your own machines

Agent SDK

The Python SDK includes a small agent loop plus provider adapters and a MIOSA tool catalogue. This is the quickest path when you want an LLM to operate MIOSA computers directly.

from miosa.agent import Agent, groq_provider

agent = Agent(
    provider=groq_provider(
        api_key="gsk_...",
        model="moonshotai/kimi-k2-instruct-0905",
    ),
    miosa_api_key="msk_live_...",
)

result = agent.run(
    "Create a sandbox, write /workspace/hello.py, run it, show me the output, "
    "then destroy the sandbox.",
    max_iterations=10,
)

print(result.final_text)

Built-in agent tools expose the computer primitive in plain terms:

Tool Does
create_sandbox Boot a fast code sandbox computer for shell/Python/Node/files.
create_computer Boot a general MIOSA computer for GUI, services, previews, files.
list_computers List active computers, sandboxes, and desktops.
get_computer Fetch status, template, size, and public URL.
exec / exec_python Run bash or Python inside the computer.
read_file / write_file / list_files Work with files inside the computer.
preview_url Get the public HTTPS URL for a service port.
destroy_computer Release compute resources when done.

Provider factories include openai_provider, groq_provider, deepseek_provider, openrouter_provider, together_provider, fireworks_provider, mistral_provider, cerebras_provider, perplexity_provider, xai_provider, ollama_provider, lm_studio_provider, and openai_compatible_provider for custom routers.

Sandbox-first builder examples live in examples/:

See BUILDER_GUIDE.md for the full “build your own Lovable with MIOSA sandboxes” product pattern.

Example What it builds
agent_sandbox_website_builder.py A Lovable-style website builder flow.
agent_sandbox_app_builder.py A small app builder with a dev server and preview.
agent_sandbox_artifact_builder.py Markdown/doc artifacts in /workspace/artifacts.
agent_sandbox_slide_deck_builder.py A deck workspace under /workspace/deck.

Set GROQ_API_KEY and MIOSA_API_KEY, then run one of the examples. They keep the sandbox alive with miosa_tool_options={"allow_destroy": False} so your app can show previews, inspect generated files, or publish later.

File operations

# Write / read
computer.files.write_file("/workspace/config.json", '{"key": "value"}')
text = computer.files.read_file("/workspace/config.json")

# Upload / download
computer.files.upload("/local/report.pdf", "/workspace/report.pdf")
raw_bytes = computer.files.download("/workspace/report.pdf")

# List / stat / mkdir / rename / chmod
entries = computer.files.list("/workspace")
stat    = computer.files.stat("/workspace/config.json")
computer.files.mkdir("/workspace/output", recursive=True)
computer.files.rename("/workspace/old.txt", "/workspace/new.txt")
computer.files.chmod("/workspace/run.sh", 0o755)

Services (background processes)

svc = computer.services.create(
    name="api",
    command="uvicorn app:main --port 8080",
    working_dir="/workspace",
    env={"DEBUG": "1"},
    port=8080,
)

for log in computer.services.logs(svc.id, follow=True):
    print(log.stream, log.line)

computer.services.restart(svc.id)
computer.services.delete(svc.id)

Desktop control

screenshot = computer.screenshot()          # PNG bytes
computer.click(640, 400)
computer.double_click(640, 400)
computer.type("hello world")
computer.key("Return")
computer.scroll("down", 3)
computer.drag(100, 100, 400, 400)

cursor = computer.cursor()
windows = computer.windows()
computer.launch("firefox")

Async usage

import asyncio
from miosa import AsyncMiosa

async def main():
    async with AsyncMiosa(api_key="msk_live_...") as miosa:
        computer = await miosa.computers.create(
            name="async-build", template_type="miosa-sandbox"
        )
        await computer.files.write_file("/workspace/app.py", "print('async!')")
        result = await computer.exec.run("python /workspace/app.py")
        print(result.stdout)
        await computer.destroy()

asyncio.run(main())

White-label / multi-tenant

Tag resources with external_workspace_id and external_user_id to attribute usage to your downstream customers:

computer = miosa.computers.create(
    name="customer-build",
    template_type="miosa-sandbox",
    metadata={
        "external_workspace_id": "dental-office-123",
        "external_user_id": "dr-smith-456",
    },
)

Docker Deploy

Use Docker Deploy when a sandbox-built app should run as a container on the workspace Docker appliance.

templates = miosa.deployments.list_docker_deploy_templates(
    framework="nextjs",
    include_preview=True,
)
template = templates[0]

miosa.deployments.ensure_docker_deploy_host(
    workspace_id="workspace-uuid",
    size="small",
)

sandbox = miosa.sandboxes.create(template_id="nextjs")
# Build or sync the app into /workspace...

published = sandbox.deploy_docker(
    name="customer-site",
    output_path="/workspace",
    port=3000,
    docker_deploy_template_id=template.id,
)

deployment_id = published.get("deployment_id") or published["id"]
proof = miosa.deployments.doctor_docker_deploy(deployment_id, probe_path="/")

if not proof.ok:
    raise RuntimeError([check.model_dump() for check in proof.checks])

Template responses include app files plus optional design_md, design_source_url, design_sources, and design_reference_presets so agents can generate the app with the same design context they later attach to the Docker Deploy publish.

Error handling

from miosa import (
    AuthenticationError, NotFoundError, RateLimitError, MiosaError
)

try:
    computer = miosa.computers.get("cmp_doesnt_exist")
except NotFoundError:
    print("Computer not found")
except RateLimitError as e:
    print(f"Rate limited; retry after {e.retry_after}s")
except AuthenticationError:
    print("Check your API key")
except MiosaError as e:
    print(f"API error {e.status}: {e.message}")

Exception hierarchy: MiosaError > AuthenticationError (401), InsufficientCreditsError (402), PermissionError (403), NotFoundError (404), ValidationError (422), RateLimitError (429), ServerError (5xx), ConnectionError, TimeoutError.

Configuration

Option Env var Default
api_key MIOSA_API_KEY
base_url MIOSA_BASE_URL https://api.miosa.ai/api/v1
timeout 30s
max_retries 3

Links

Phase 1-4 methods (v1.1.0)

Preview tokens and share URLs

# Mint a scoped preview token (e.g. for iframe embed)
token = sb.preview_token(expires_in=3600, scope="read")
print(token["url"])  # https://...?mt=mp_<token>

# Create a public share link (no API key required)
share = sb.share.create(expires_in=7200)
print(share["share_url"])

File tree and batch write

tree = sb.files.tree("/workspace", depth=2)
sb.files.write_many([
    {"path": "/workspace/app.py", "content": "print('hello')"},
    {"path": "/workspace/cfg.json", "content": b"{}"},
])

Tenant events stream and quotas

for event in client.events.stream(types=["sandbox.*"]):
    print(event["_event_type"], event)

client.quotas.set("usr_abc", max_sandboxes=10, max_concurrent=3)

Webhook signature verification

from miosa.resources.webhooks import Webhooks

ok = Webhooks.verify_signature(request.body, request.headers["X-Miosa-Signature"], secret)

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

miosa-1.2.3.tar.gz (199.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

miosa-1.2.3-py3-none-any.whl (156.1 kB view details)

Uploaded Python 3

File details

Details for the file miosa-1.2.3.tar.gz.

File metadata

  • Download URL: miosa-1.2.3.tar.gz
  • Upload date:
  • Size: 199.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for miosa-1.2.3.tar.gz
Algorithm Hash digest
SHA256 4b48a1cf1a66160d43029754b93302723542679886d4b10c03d8d07ab07a88a6
MD5 d2663446be919e4dfe9290b402dae71c
BLAKE2b-256 e1cd540169f0feffc6f2f6c0019d0d3b65caf07fd5be7aa66b9845d8fbe6c505

See more details on using hashes here.

File details

Details for the file miosa-1.2.3-py3-none-any.whl.

File metadata

  • Download URL: miosa-1.2.3-py3-none-any.whl
  • Upload date:
  • Size: 156.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for miosa-1.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 8334a715d10fbc851a0c1452f45da928def68adac6c121824b99423f6179b27e
MD5 36affc048d921cf946d55c2d0821aaff
BLAKE2b-256 959bc9205e90952df70e311bde7cc92c0bb890e565f68216fe49e1c59a826803

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page