Skip to content

Quick start

Install

pip install ailoy-py

The model runs on a CLI you are logged in to (Claude Code, for the Claude model on this page) or on an API key. Installation covers the machine the sandbox needs, API keys, and fixes for common errors.

Run an agent

An agent needs only a model. This one has no tools and no sandbox, so it answers from what the model knows:

import asyncio
from ailoy import AgentBuilder
async def main() -> None:
agent = await (
# For openai, use "openai/gpt-6-luna"
AgentBuilder("anthropic/claude-haiku-5-5")
.build()
)
async for output in agent.run("What is the meaning of hello world?"):
for part in output["message"]["contents"]:
if part["type"] == "text":
print(part["text"])
asyncio.run(main())

agent.run yields each message of the turn as it completes; Running an agent covers what it yields and how to stream it instead.

Give it a sandbox

The same agent with a sandbox can install software, write and run code, and keep files, in a Linux microVM of its own rather than on your machine. The added lines start virtx’s server, make a sandbox from a Python image, hand it to the agent, and copy the chart the agent draws out to population.png:

import asyncio
from pathlib import Path
from ailoy import AgentBuilder
from virtx import Client
async def main() -> None:
# Starts virtx's server, fetched into its cache the first time.
client = Client.spawn()
await client.pull_image("python:3.12-slim-trixie").complete()
sandbox = await client.create_sandbox("python:3.12-slim-trixie")
agent = await (
# For openai, use "openai/gpt-6-luna"
AgentBuilder("anthropic/claude-haiku-5-5")
.instruction("Write what you are asked for into /artifacts.")
.sandbox(sandbox)
.build()
)
async for output in agent.run("Create a bar chart comparing the populations of European countries and save it to /artifacts/population.png."):
for part in output["message"]["contents"]:
if part["type"] == "text":
print(part["text"])
Path("population.png").write_bytes(await sandbox.read_file("artifacts/population.png"))
asyncio.run(main())

The image has no matplotlib, so the agent installs it with the shell that sandbox(...) gives it, along with file tools (Tools).

What happened