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

# Filesystem

> Copy files to and from a Devbox, and work with them in place.

Give your agent its inputs and collect what it produces. Files stay on the Devbox when it stops. See [Persistence](https://namespace.so/docs/devbox/persistence.md).

> [!TIP]
>
> With the [Devbox skill](https://namespace.so/docs/reference/devbox-cli/agent-skills.md), ask your agent in plain language, for example: *"copy my local changes to the devbox"*

## Copy files to and from your machine

```bash CLI theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
# Copies a file, or a directory and its contents.
# Your machine → Devbox
devbox upload my-devbox ./config.json config.json
# Devbox → your machine
devbox download my-devbox build.log ./build.log

# Create missing parent directories:
devbox upload my-devbox ./config.json new/config.json --mkdir

# Print a file to standard output:
devbox download my-devbox build.log -
```

```typescript TS SDK theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
const devbox = await client.devboxes.get("my-devbox");

// One file at a time; directories aren't copied.
// Your machine → Devbox
await devbox.fs.upload("./config.json", "config.json");
// Devbox → your machine
await devbox.fs.download("build.log", "./build.log");

// Track a large transfer:
await devbox.fs.upload("./data.tar", "data.tar", {
  onProgress: (sent, total) => console.log(`${sent} / ${total} bytes`),
});
```

Relative paths start in the Devbox's workspace directory on Linux and macOS.

## Read and write files

Read and write files in the Devbox without copying them to your machine.

```bash CLI theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
devbox exec my-devbox -- sh -c 'printf "hello\n" > notes.txt'

devbox exec my-devbox -- cat notes.txt
```

```typescript TS SDK theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
await devbox.fs.writeFile("notes.txt", "hello\n");

// Text by default:
const text = await devbox.fs.read("notes.txt");

// Binary data, or part of a file:
const bytes = await devbox.fs.read("image.png", {
  format: "bytes",
  offset: 0,
  length: 1024,
});

// A large file, as a stream:
const stream = await devbox.fs.read("build.log", { format: "stream" });
for await (const chunk of stream) {
  process.stdout.write(chunk);
}
```

## Manage files and directories

### Create and inspect

```bash CLI theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
# Linux and macOS
devbox exec my-devbox -- mkdir -p output
devbox exec my-devbox -- ls output
devbox exec my-devbox -- test -e output/report.txt
```

```typescript TS SDK theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
await devbox.fs.mkdir("output", { recursive: true });
const entries = await devbox.fs.readdir("output"); // each has a name and a type
const exists = await devbox.fs.exists("output/report.txt");
```

### Copy, move, and delete

```bash CLI theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
# Linux and macOS
devbox exec my-devbox -- cp -r src src-backup
devbox exec my-devbox -- mv notes.txt output/notes.txt
devbox exec my-devbox -- rm -r src-backup
```

```typescript TS SDK theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
await devbox.fs.copy("src", "src-backup", { recursive: true });
await devbox.fs.rename("notes.txt", "output/notes.txt");
// Without recursive, removes only a file or an empty directory.
await devbox.fs.remove("src-backup", { recursive: true });
```

## Related

* [Run commands](https://namespace.so/docs/devbox/exec.md) to run commands that create or change files.
* [Persistence](https://namespace.so/docs/devbox/persistence.md) for what happens to files when a Devbox stops.
* Reference: [SDK files](https://namespace.so/docs/reference/typescript-sdk/devbox/files.md), [`devbox upload`](https://namespace.so/docs/reference/devbox-cli/upload), [`devbox download`](https://namespace.so/docs/reference/devbox-cli/download).


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