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

Hex version Hex downloads License: MIT Docs

Elixir 1.15+. HTTP transport via Req, JSON via Jason.

Install

def deps do
  [
    {:miosa, "~> 1.0"}
  ]
end

Then run mix deps.get.

Quickstart

client = Miosa.client("msk_live_...")

{:ok, computer} = Miosa.Computers.create(client, %{
  name: "my-build",
  template_type: "miosa-sandbox",
  size: "small"
})

{:ok, result} = Miosa.Exec.bash(client, computer.id, "echo 'hello from miosa'")
IO.puts(result.output)  # hello from miosa

{:ok, _} = Miosa.Files.write_file(client, computer.id, "/workspace/app.exs", ~s(IO.puts("hi")))
{:ok, text} = Miosa.Files.read_file(client, computer.id, "/workspace/app.exs")

:ok = Miosa.Computers.delete(client, computer.id)

What's included

ModuleDescription
Computers
Miosa.ComputersCreate, list, get, update, delete computers
Miosa.ComputerBound handle — start, stop, restart, clone, resize, wait
Miosa.Computer.AgentCUA sessions — run, list, get, cancel AI agent sessions
Miosa.Computer.EnvPer-computer environment variables
Miosa.Computer.LogsComputer log retrieval + SSE streaming
Miosa.Computer.MetricsCPU/memory metrics
Miosa.Computer.PortsPort mapping CRUD
Miosa.Computer.TerminalPTY session create + resize
Miosa.Computer.VolumesAttach/detach volumes to computers
Miosa.Computer.AutoStopAuto-stop timer get/update
Miosa.Computer.InboxComputer inbox get/update
Miosa.Computer.OsaOSA agent task submit/cancel/configure
Desktop
Miosa.DesktopScreenshot, click, double_click, right_click, type, key, hotkey, scroll, drag, move, launch, windows, cursor, focus_window
Exec & Files
Miosa.Execbash/4, python/4, spawn/4 execution inside VMs
Miosa.Exec.CommandWebSocket PTY — send_stdin, resize, await
Miosa.FilesUpload, download, write, read, list, stat, mkdir, rename, copy, chmod, delete, export
Sandboxes
Miosa.SandboxesCreate, list, get, delete sandboxes + wait_until_ready
Miosa.Sandbox.ProcessesBackground process start/list/kill/send_stdin
Miosa.Sandbox.EventsSSE event streaming + file watch
Miosa.Sandbox.PreviewsPreview URL create/list/share/revoke
Miosa.Sandbox.TerminalSandbox PTY session create/delete
Miosa.Sandbox.EnvSandbox environment variables
Miosa.Sandbox.TagsSandbox tag management
Miosa.SandboxTemplatesTemplate CRUD + builds
Deployments
Miosa.DeploymentsCreate, list, publish, rollback, versions, releases, builds, env, domains, runtime instances
Data
Miosa.DatabasesCreate, list, get, delete, start/stop/restart, credentials, logs
Miosa.StorageBuckets CRUD + objects put/get/delete/list + presign
Miosa.VolumesVolume CRUD
Platform
Miosa.FunctionsEdge functions CRUD + invoke
Miosa.WebhooksWebhook CRUD + test + deliveries
Miosa.CronJobsCron job CRUD + pause/resume/run_now + executions
Miosa.ApiKeysAPI key CRUD
Miosa.WorkspacesWorkspace CRUD + list_computers
Miosa.CustomDomainsCustom domain register/verify/delete
Miosa.NetworkPolicyNetwork policy get/set/reset
Miosa.ServicesService CRUD + start/stop/restart/logs
Miosa.CheckpointsSnapshot create/list/restore/delete
Miosa.EventsSSE event streaming per computer
Miosa.SettingsPlatform settings + branding
Miosa.CreditsCredit balance + transactions
Miosa.CompletionsChat/text completions + SSE streaming
Miosa.RegionsAvailable regions
BYOC & Admin
Miosa.OpenComputersBYOC host management (hosts, jobs, tunnels, agents, clusters, secrets)
Miosa.AdminAdmin-scoped operations (dashboard, users, tenants, credits, plans)

Exec

{:ok, result} = Miosa.Exec.bash(client, computer.id, "ls -la /workspace",
  timeout: 10_000,
  working_dir: "/workspace",
  env: %{"DEBUG" => "1"}
)
IO.puts(result.stdout)
IO.puts("exit: #{result.exit_code}")

{:ok, py} = Miosa.Exec.python(client, computer.id, """
  import json
  print(json.dumps({"status": "ok"}))
""")
IO.puts(py.output)

File operations

# Write / read
{:ok, _} = Miosa.Files.write_file(client, id, "/workspace/app.py", "print('hi')")
{:ok, text} = Miosa.Files.read_file(client, id, "/workspace/app.py")

# Upload binary
{:ok, _} = Miosa.Files.upload(client, id, "./local.txt", "/workspace/remote.txt")

# List / stat / mkdir / rename / delete
{:ok, entries} = Miosa.Files.list(client, id, "/workspace")
{:ok, stat}    = Miosa.Files.stat(client, id, "/workspace/app.py")
{:ok, _}       = Miosa.Files.mkdir(client, id, "/workspace/output")
{:ok, _}       = Miosa.Files.rename(client, id, "/workspace/old.py", "/workspace/new.py")
:ok            = Miosa.Files.delete(client, id, "/workspace/old.py")

Desktop control

{:ok, png} = Miosa.Desktop.screenshot(client, computer.id)
File.write!("screen.png", png)

:ok = Miosa.Desktop.click(client, computer.id, 640, 400)
:ok = Miosa.Desktop.double_click(client, computer.id, 640, 400)
:ok = Miosa.Desktop.right_click(client, computer.id, 640, 400)
:ok = Miosa.Desktop.type(client, computer.id, "hello world")
:ok = Miosa.Desktop.key(client, computer.id, "Return")
:ok = Miosa.Desktop.key(client, computer.id, "ctrl+c")
:ok = Miosa.Desktop.scroll(client, computer.id, 640, 400, "down", 3)
:ok = Miosa.Desktop.drag(client, computer.id, 100, 100, 400, 400)

{:ok, windows} = Miosa.Desktop.windows(client, computer.id)
{:ok, cursor}  = Miosa.Desktop.cursor(client, computer.id)
:ok            = Miosa.Desktop.launch(client, computer.id, "firefox")

SSE event streaming

:ok = Miosa.Events.stream(client, computer.id, fn event ->
  IO.inspect({event.type, event.data})
end)

OTP / Supervisor integration

children = [
  {Miosa.Client, api_key: System.fetch_env!("MIOSA_API_KEY")}
]

Supervisor.start_link(children, strategy: :one_for_one)

Phoenix / LiveView integration

defmodule MyAppWeb.SandboxLive do
  use Phoenix.LiveView

  def mount(_params, _session, socket) do
    client = Miosa.client(System.fetch_env!("MIOSA_API_KEY"))
    {:ok, assign(socket, client: client, output: nil)}
  end

  def handle_event("run", %{"cmd" => cmd}, socket) do
    {:ok, result} = Miosa.Exec.bash(
      socket.assigns.client,
      socket.assigns.computer_id,
      cmd
    )
    {:noreply, assign(socket, output: result.output)}
  end
end

White-label / multi-tenant

{:ok, computer} = Miosa.Computers.create(client, %{
  name: "customer-build",
  template_type: "miosa-sandbox",
  metadata: %{
    "external_workspace_id" => "acme-corp",
    "external_user_id"      => "user-99"
  }
})

Error handling

All functions return {:ok, result} or {:error, %Miosa.Error{}}:

case Miosa.Computers.get(client, "cmp_doesnt_exist") do
  {:ok, computer} ->
    computer

  {:error, %Miosa.Error{status: 404}} ->
    IO.puts("not found")

  {:error, %Miosa.Error{status: 429, message: msg}} ->
    IO.puts("rate limited: #{msg}")

  {:error, %Miosa.Error{message: msg}} ->
    IO.puts("error: #{msg}")
end

Miosa.Error fields: :message, :status, :code, :body.

Configuration

client = Miosa.client("msk_live_...",
  base_url:        "https://api.miosa.ai/api/v1",
  timeout:         30_000,
  receive_timeout: 60_000,
  retry:           false
)
OptionDefault
:api_keyrequired — pass explicitly; env var not auto-read
:base_urlhttps://api.miosa.ai/api/v1
:timeout30_000 ms
:receive_timeout60_000 ms
:retryfalse

License

MIT