# Drive machines from Python or TypeScript

Call OSMates from Python or TypeScript, or give an AI model a machine's desktop through a computer-use tool.

The SDKs run the [command line](https://osmates.com/docs/install#add-the-command-line) for each call, and drive the machines of the Mac they run on.

## Install an SDK

Get a copy of the OSMates repository, then open its folder in Terminal.

For Python 3.9 or later, install the core, and the extra for each vendor's driver you use:

```sh
pip install ./sdk/python
pip install './sdk/python[anthropic]'
pip install './sdk/python[openai]'
```

For Node 22.18 or later, pack the SDK:

```sh
cd sdk/typescript
npm ci
npm pack
```

Then install the package in your project, with the repository's path for `<repository>`. For a driver, also install `@anthropic-ai/sdk@1.8.0` or `openai@7.55.0`.

```sh
npm install <repository>/sdk/typescript/osmates-sdk-0.1.0.tgz
```

## Run a command in a clone

In Python:

```python
from osmates import OSMates

client = OSMates()
result = client.run(["uname", "-a"], source="dev")
print(result.exit_code, result.stdout_text)
```

In TypeScript:

```ts
import { OSMates } from '@osmates/sdk';

const client = new OSMates();
const result = await client.run(['uname', '-a'], { source: 'dev' });
console.log(result.exitCode, result.stdoutText);
```

This clones `dev`, runs the command, and deletes the clone, as [`osmates run`](https://osmates.com/docs/clone#run-one-command-in-a-temporary-clone) does. The Python and TypeScript READMEs list every method.

## Allow your program

Your program is an AI agent to OSMates. It goes through [`osmates agent`](https://osmates.com/docs/agent-cli), so permissions and access limits apply as for any agent.

1. Run your program.
2. When the question window opens on your Mac, click **Allow**.

While the question waits, the SDK repeats the call for up to 10 minutes. The question names the Python or Node that runs the SDK. Use one you installed, such as Homebrew's: a program OSMates can't identify gets access for its current session only.

The first change takes a snapshot, and [Take Control](https://osmates.com/docs/agent-control#take-control) pauses your program. For a job that runs while you're away, [give access before the agent asks](https://osmates.com/docs/agent-access#give-access-before-the-agent-asks).

## Give a model a machine's desktop

Each driver connects a machine to a vendor's computer-use tool:

| SDK | Anthropic | OpenAI |
|---|---|---|
| Python | `OSMatesComputer` in `osmates.anthropic` | `OSMatesComputerDriver` in `osmates.openai` |
| TypeScript | `OSMatesComputer` in `@osmates/sdk/anthropic` | `OSMatesComputerDriver` in `@osmates/sdk/openai` |

In Python, with Anthropic's SDK:

```python
import anthropic
from osmates.anthropic import OSMatesComputer

with OSMatesComputer("win") as desktop:
    runner = anthropic.Anthropic().beta.messages.tool_runner(
        model="claude-opus-5-5",
        max_tokens=16000,
        tools=[desktop],
        messages=[{"role": "user", "content": "Open Notepad and type hello."}],
    )
    for message in runner:
        print(message.content)
```

The model sees screenshots 1280 pixels on the long edge, and its clicks land on that screenshot's pixels. An action that changes the machine waits for your permission, and doesn't run if you refuse.

Close the driver when the task ends. Until then, other agents can't drive the machine.

## Run benchmarks

The Python SDK has a provider for OSWorld and an environment for Harbor. By default, each task runs in a clone that's deleted afterwards. The Python SDK's README has the setup. Harbor's Compose tasks aren't supported.
