> ## Documentation Index
> Fetch the complete documentation index at: https://docs.archil.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Workspaces

> Combine several disks into one filesystem for your code and your agents.

A workspace combines several disks into one filesystem. Each disk appears as a top-level directory under the name you
give it, so `source/README.md` is `README.md` on the disk named `source`. A workspace has the same file methods as a
single disk, which makes it a drop-in filesystem for [agent tools](https://docs.archil.com/integrations/ai-sdk.md) that should see more than one
disk.

## Create a workspace

Map a name to each disk. To change how a disk is mounted, pass an object with the disk and its options instead:

* `readOnly`: reads work and writes return an error.
* `subdirectory`: mount only part of the disk.
* `conditional`: write without exclusive access, so several clients can write to the disk at once. See
  [sharing disks](https://docs.archil.com/concepts/sharing-disks.md).

```typescript TypeScript theme={null}
import * as archil from "disk";

const source = await archil.getDisk("dsk-source123");
const output = await archil.getDisk("dsk-output456");

const workspace = archil.workspace({
  source: { disk: source, readOnly: true },
  output,
});
```

```python Python theme={null}
import archil
from archil import ExecMountSpec

source = archil.get_disk("dsk-source123")
output = archil.get_disk("dsk-output456")

workspace = archil.workspace({
    "source": ExecMountSpec(disk=source, read_only=True),
    "output": output,
})
```

`workspace` is also a method on an `Archil` client, for code that uses [more than one account or region](https://docs.archil.com/sdks/overview.md#multiple-accounts-or-regions).

## Read, write, and search

Keys start with the disk's name. Reads and writes go to that disk. Listing or searching from the workspace root covers
every disk.

```typescript TypeScript theme={null}
const readme = await workspace.getObject("source/README.md");
await workspace.putObject("output/summary.md", "# Summary\n");

const top = await workspace.listObjects("");                    // one entry per disk
const reports = await workspace.listObjects("output/reports/");

const hits = await workspace.grep({ directory: "", pattern: "TODO", recursive: true });
```

```python Python theme={null}
readme = workspace.get_object("source/README.md")
workspace.put_object("output/summary.md", "# Summary\n")

top = workspace.list_objects("")                  # one entry per disk
reports = workspace.list_objects("output/reports/")

hits = workspace.grep(directory="", pattern="TODO", recursive=True)
```

`grep` takes the same options as on a disk. See [search files](https://docs.archil.com/compute/search-files.md).

## Run commands

`exec` runs a command with every disk mounted at `/mnt/archil/<name>`, with each disk's mount options applied. See
[serverless execution](https://docs.archil.com/compute/serverless-execution.md).

```typescript TypeScript theme={null}
const { stdout } = await workspace.exec("wc -l /mnt/archil/source/*.csv > /mnt/archil/output/counts.txt");
```

```python Python theme={null}
result = workspace.exec("wc -l /mnt/archil/source/*.csv > /mnt/archil/output/counts.txt")
```

## Change disks

Add or replace a disk with `addDisk` and remove one with `removeDisk` (`add_disk` and `remove_disk` in Python).
`diskNames` lists the current names. A workspace always keeps at least one disk.

```typescript TypeScript theme={null}
workspace.addDisk("scratch", await archil.getDisk("dsk-scratch789"));
workspace.removeDisk("scratch");
console.log(workspace.diskNames()); // ["source", "output"]
```

```python Python theme={null}
workspace.add_disk("scratch", archil.get_disk("dsk-scratch789"))
workspace.remove_disk("scratch")
print(workspace.disk_names())  # ["source", "output"]
```

## Give a workspace to an agent

Pass a workspace wherever an integration takes a disk. The agent sees each disk as a directory, and read-only disks
stay read-only.

```typescript TypeScript theme={null}
import { createDiskTools } from "@archildata/ai-sdk";

const tools = createDiskTools(workspace);
```

```python Python theme={null}
tools = workspace.agent_tools().for_openai_agents()
```

See [AI SDK](https://docs.archil.com/integrations/ai-sdk.md), [Mastra](https://docs.archil.com/integrations/mastra.md), [LangChain.js](https://docs.archil.com/integrations/langchain.md),
[eve](https://docs.archil.com/integrations/eve.md), and [Python agent tools](https://docs.archil.com/integrations/python-agent-tools.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.