> ## 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.

# Caching

> Share build caches across Devboxes so your agent doesn't rebuild from scratch.

> [!NOTE]
>
> Every Devbox comes with Namespace's remote build caches. The [`nsc` CLI](https://namespace.so/docs/reference/cli/installation) is installed and logged in on every Devbox, so commands run in it reach the caches with no setup.

Say your agent splits work into five tasks and creates a Devbox for each, then builds the project in all five. Without a shared cache, every Devbox builds it from scratch. With one, the first Devbox to build a piece of code uploads the result, and the others download it instead. Only the code a task changed gets rebuilt.

These are remote caches that your build tools reach over the network, not cache volumes attached to the Devbox.

## Try it with Bazel

Build the same target on two Devboxes. The second one reports a remote cache hit instead of rebuilding.

**1. Set up the cache**

```bash CLI theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
devbox exec my-devbox -- \
  nsc cache bazel setup --bazelrc /tmp/ns.bazelrc
```

```typescript TS SDK theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
await devbox.exec([
  "nsc", "cache", "bazel", "setup",
  "--bazelrc", "/tmp/ns.bazelrc",
]);
```

On Windows, add `--static` and write the bazelrc to a Windows path, then pass that path when you build:

```bash theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
devbox exec my-devbox -- powershell.exe -Command \
  'nsc cache bazel setup --static --bazelrc C:\Users\runneradmin\ns.bazelrc'
```

**2. Build with it**

```bash CLI theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
devbox exec my-devbox -- sh -c \
  'cd /workspaces/my-repo && bazel --bazelrc=/tmp/ns.bazelrc build //...'
```

```typescript TS SDK theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
await devbox.exec(
  ["bazel", "--bazelrc=/tmp/ns.bazelrc", "build", "//..."],
  { cwd: "/workspaces/my-repo" },
);
```

Run the setup once in each Devbox, before its first build. When a second Devbox builds the same targets, Bazel reports remote cache hits and skips the work the first one already did.

## Set up a cache for your build tool

Run your tool's setup command in the Devbox, the same way you [run any other command](https://namespace.so/docs/devbox/exec.md):

| Tool | Setup command | What it does |
| - | - | - |
| Bazel | `nsc cache bazel setup --bazelrc /tmp/ns.bazelrc` | Writes a bazelrc that points Bazel at the cache. See [Bazel cache](https://namespace.so/docs/bazel/cache.md). |
| Gradle | `nsc gradle cache setup --user` | Configures every Gradle build in the Devbox to use the cache. See [Gradle](https://namespace.so/docs/integrations/gradle.md). |
| Turborepo | `nsc cache turborepo setup --team default` | Prints the environment variables Turborepo reads. See [Turborepo](https://namespace.so/docs/integrations/turborepo.md). |

Pants, sccache, and Buck2 have remote caches too. See [`nsc cache pants setup`](https://namespace.so/docs/reference/cli/pants-cache-setup), [`nsc cache sccache setup`](https://namespace.so/docs/reference/cli/sccache-setup), and [`nsc cache buck2 setup`](https://namespace.so/docs/reference/cli/cache-buck2-setup).


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