> For the complete documentation index, see [llms.txt](https://docs.orchard.airoverflow.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.orchard.airoverflow.com/quickstart/typescript.md).

# TypeScript / JavaScript

Install `@orchard/sdk` and set `ORCHARD_API_URL` + `ORCHARD_API_KEY` (see [Authentication](/auth.md)). The package is ESM + CJS; `import` and `require` both work, and it runs in Node and the browser.

## Connect and list

```ts
import { Orchard } from "@orchard/sdk";

const orchard = Orchard.fromEnv();           // or new Orchard({ url, token })

const me = await orchard.me();
console.log("acting as", me.username);

const { instances } = await orchard.sandboxes.list();
for (const s of instances) console.log(s.name, s.state, s.tag ?? "-");
```

CommonJS:

```js
const { Orchard } = require("@orchard/sdk");
```

## Address one sandbox

`orchard.sandbox(selector)` resolves a **uuid**, **uuid prefix**, **name** or **tag**:

```ts
const sb = await orchard.sandbox("my-pixel");
await sb.start();
await sb.tag("payments", "#22c55e");
await sb.edit({ notes: "under test" });
```

Ambiguous or missing selectors throw `SelectorError`.

## Create a sandbox

```ts
const job = await orchard.sandboxes.create({
  platform: "android",
  name: "ci-pixel",
  image: "system-images;android-35;google_apis;x86_64",
  device: "pixel_7",
  cpu: 4,
  memory_mb: 4096,
});
console.log("launching on", (job as any).node);
```

## Stream logs

Channels are async-iterable; `break` (or `.close()`) ends the stream:

```ts
for await (const line of sb.logs()) {
  console.log(line);
}
```

Or event-style:

```ts
const ch = sb.logs();
ch.on("message", (line) => console.log(line));
ch.on("close", () => console.log("done"));
```

## Files and apps

```ts
// Node: wrap a buffer in a File (Node ≥ 20 has global File)
import { readFile } from "node:fs/promises";
const apk = new File([await readFile("./app.apk")], "app.apk");
await sb.apps.install(apk);

const pdf = await sb.files.download("/sdcard/Download/report.pdf"); // Uint8Array
```

## Error handling

```ts
import { ApiError, SelectorError } from "@orchard/sdk";

try {
  await orchard.sandbox("nope");
} catch (e) {
  if (e instanceof SelectorError) console.log("no match");
  if (e instanceof ApiError) console.log(e.status, e.message);
}
```

Next: [Scoped API keys](/guides/scoped-api-keys.md) · [Live channels](/guides/live-channels.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.orchard.airoverflow.com/quickstart/typescript.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
