# Quick start

https://ailoy.co/docs/guides/quick-start/

Run an agent for one turn, then give it a sandbox and let it make a chart.

## Install

**Python**

```sh
pip install ailoy-py
```

**Node.js**

```sh
npm install @brekkylab/ailoy
```

**Rust**

```sh
cargo add ailoy virtx futures anyhow tokio --features tokio/macros,tokio/rt-multi-thread
```

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](https://ailoy.co/docs/guides/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:

**Python**

```python
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())
```

**Node.js**

```js
const { AgentBuilder } = require('@brekkylab/ailoy')

async function main() {
  // For openai, use "openai/gpt-6-luna"
  const agent = await new AgentBuilder('anthropic/claude-haiku-5-5')
    .build()

  for await (const { message } of agent.run('What is the meaning of hello world?')) {
    for (const part of message.contents) {
      if (part.type === 'text') console.log(part.text)
    }
  }

  await agent.close()
}

main()
```

**Rust**

```rust
use ailoy::{
    agent::AgentBuilder,
    message::{Message, Part, Role},
};
use futures::StreamExt as _;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    // For openai, use "openai/gpt-6-luna"
    let mut agent = AgentBuilder::new("anthropic/claude-haiku-5-5")
        .build()
        .await?;

    let query = Message::new(Role::User).with_contents([Part::text("What is the meaning of hello world?")]);
    let mut stream = agent.run(query);
    while let Some(output) = stream.next().await {
        let message = output?.message;
        if message.role == Role::Assistant {
            for text in message.contents.iter().filter_map(Part::as_text) {
                println!("{text}");
            }
        }
    }

    Ok(())
}
```

`agent.run` yields each message of the turn as it completes; [Running an agent](https://ailoy.co/docs/guides/running/) 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`:

**Python**

```python ins={2,5,9-13,18-19,28} mark={23}
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())
```

**Node.js**

```js ins={1,3,6-9,13-14,23,25} mark={17}
const { writeFileSync } = require('node:fs')
const { AgentBuilder } = require('@brekkylab/ailoy')
const { Client } = require('@brekkylab/virtx')

async function main() {
  // Starts virtx's server, fetched into its cache the first time.
  const client = Client.spawn()
  await client.pullImage('python:3.12-slim-trixie').complete()
  const sandbox = await client.createSandbox('python:3.12-slim-trixie')

  // For openai, use "openai/gpt-6-luna"
  const agent = await new AgentBuilder('anthropic/claude-haiku-5-5')
    .instruction('Write what you are asked for into /artifacts.')
    .sandbox(sandbox)
    .build()

  for await (const { message } of agent.run('Create a bar chart comparing the populations of European countries and save it to /artifacts/population.png.')) {
    for (const part of message.contents) {
      if (part.type === 'text') console.log(part.text)
    }
  }

  writeFileSync('population.png', await sandbox.readFile('artifacts/population.png'))
  await agent.close()
  await client.close()
}

main()
```

**Rust**

```rust ins={6,10-18,22-23,38-39} mark={27}
use ailoy::{
    agent::AgentBuilder,
    message::{Message, Part, Role},
};
use futures::StreamExt as _;
use virtx::{Client, Files as _, SandboxCreateArgs};

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    // Starts virtx's server, fetched into its cache the first time.
    let client = Client::spawn_virtx([] as [&str; 0]).await?;
    client.pull_image("python:3.12-slim-trixie", None).complete(false).await?;
    let sandbox = client
        .create_sandbox(&SandboxCreateArgs::new("python:3.12-slim-trixie"))
        .await?;

    // For openai, use "openai/gpt-6-luna"
    let mut agent = AgentBuilder::new("anthropic/claude-haiku-5-5")
        .instruction("Write what you are asked for into /artifacts.")
        .sandbox(sandbox.clone())
        .build()
        .await?;

    let query = Message::new(Role::User).with_contents([Part::text("Create a bar chart comparing the populations of European countries and save it to /artifacts/population.png.")]);
    let mut stream = agent.run(query);
    while let Some(output) = stream.next().await {
        let message = output?.message;
        if message.role == Role::Assistant {
            for text in message.contents.iter().filter_map(Part::as_text) {
                println!("{text}");
            }
        }
    }

    let png = sandbox.read_file("artifacts/population.png", 0, None).await?;
    std::fs::write("population.png", png)?;
    Ok(())
}
```

The image has no matplotlib, so the agent installs it with the shell that `sandbox(...)` gives it, along with file tools ([Tools](https://ailoy.co/docs/guides/tools/)).

## What happened

- [How an agent works](https://ailoy.co/docs/concepts/#a-turn) walks through the turn: the model asks for tools, they run, and their results go back to it until it answers.
- [Giving an agent a sandbox](https://ailoy.co/docs/guides/sandbox/) covers images, volumes for inputs and results, and picking up later.
- [Defining an agent](https://ailoy.co/docs/guides/agents/) lists everything else an agent can be given.
- If a step fails, [Troubleshooting](https://ailoy.co/docs/guides/installation/#troubleshooting) lists the usual errors and their fixes.
