# Let sandbox.json pin shared build caches to the workspace (Cargo CARGO\_TARGET\_DIR), not hashed cursor-sandbox-cache dirs

**URL:** <https://forum.cursor.com/t/let-sandbox-json-pin-shared-build-caches-to-the-workspace-cargo-cargo-target-dir-not-hashed-cursor-sandbox-cache-dirs/171287>\
**Category:** Feature Requests\
**Tags:** terminal, sandbox, rust\
**Created:** [September 10, 2026, 7:28pm UTC](https://forum.cursor.com/t/let-sandbox-json-pin-shared-build-caches-to-the-workspace-cargo-cargo-target-dir-not-hashed-cursor-sandbox-cache-dirs/171287 "2026-09-10T19:28:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![koliyo](https://sea3.discourse-cdn.com/cursor1/user_avatar/forum.cursor.com/koliyo/32/8940_2.png) [@koliyo](https://forum.cursor.com/u/koliyo)\
**Post date:** [September 10, 2026, 7:28pm UTC](https://forum.cursor.com/t/let-sandbox-json-pin-shared-build-caches-to-the-workspace-cargo-cargo-target-dir-not-hashed-cursor-sandbox-cache-dirs/171287/1 "2026-09-10T19:28:23Z")

</div>

### Feature request for product/service

Cursor IDE

### Describe the request

Sandboxed Agent shells inject cache env vars (`CARGO_TARGET_DIR`, `CARGO_HOME`, `RUSTUP_HOME`, npm/pip/go, …) into hashed paths like:

`/var/folders/…/T/cursor-sandbox-cache/<hash>/cargo-target`

On a large Rust workspace this is a **new multi-GB compile tree per hash**. I hit `No space left on device` (~18 GB free, APFS at 96%) while `cargo test` compiled `wasmtime-wasi` into a **2.7 GB** sandbox cache. Another **~10 GB** hash from an earlier session was still on disk. The agent then considered deleting caches and exporting `CARGO_TARGET_DIR` to the project `target/` — that is a prompt workaround, not a product setting.

I want sandboxed agents to use the **same incremental `target/` as my own terminal** , without disabling the sandbox.

### What exists today (and why it is not enough)

[`sandbox.json`](https://cursor.com/docs/reference/sandbox.md) has:

```json
{ "enableSharedBuildCache": true }

```

Docs say this redirects npm/cargo/pip caches to a **shared tmpdir** so sandboxed and unsandboxed commands share caches. That still:

1. Lives under **temp** , not the workspace `target/` I already pay for on disk.
2. Does **not** document a stable identity across chats/hashes, or a way to set the path.
3. Does **not** stop (or document) injecting `CARGO_TARGET_DIR`, which **overrides** `.cargo/config.toml` `[build] target-dir`.
4. Is incomplete in practice: staff noted that `enableSharedBuildCache: false` **does not work as expected** ([Playwright sandbox cache thread](https://forum.cursor.com/t/agent-sandbox-redirects-playwright-browsers-path-and-npm-config-devdir-to-empty-cursor-sandbox-cache-windows-playwright-reinstall-loops-npm-11-warnings/167542)).

Workarounds (agent rules that `unset`/`export` vars, Legacy Terminal, unsandboxed `all` permissions) are unreliable: env injection still happens even when FS/network jail is off ([env injection report](https://forum.cursor.com/t/shell-tool-injects-30-sandbox-cache-environment-variables-even-with-required-permissions-all-breaking-build-tools/151772)).

### Request

Add an explicit, documented way to **opt into sharing the host/workspace build directory** while keeping sandbox FS and network policy.

Sketch (names flexible):

```json
{
  "enableSharedBuildCache": true,
  "buildCache": {
    "mode": "workspace",
    "cargoTargetDir": "${workspaceFolder}/target"
  }
}

```

Modes that would cover the cases people already hit:

| Mode | Behavior |
| --- | --- |
| `isolated` (today’s default) | Hashed `cursor-sandbox-cache/<id>/…` |
| `sharedTmp` | Current `enableSharedBuildCache`: one tmpdir, sandboxed ↔ unsandboxed |
| `workspace` | Do **not** override `CARGO_TARGET_DIR` / `CARGO_HOME` / `RUSTUP_HOME` (and equivalents) when the destination is already writable via workspace or `additionalReadwritePaths` |

Also useful:

- Per-tool overrides (`cargoTargetDir`, `cargoHome`, …) so a **multi-root** window can keep one `target/` per repo and not mix artifacts.
- Document which env vars the shell injects (`CARGO_TARGET_DIR` is the expensive one for Rust incremental builds; `CARGO_HOME` is a different cache).
- Honor this when `required_permissions: ["all"]` is **not** set; isolation vs sharing should be `sandbox.json`, not “turn the sandbox off.”
- Do not require agents to `rm -rf` sandbox hashes to recover disk.

Security can stay the same: writes still only to workspace + `additionalReadwritePaths`. Sharing `./target` is not a wider FS grant.

### Why this is not just “enable the flag”

`enableSharedBuildCache` is about **tmp sharing**. Disk-constrained Rust work needs **one compile tree** , the same one rust-analyzer / my terminal already use. A hashed 3–10 GB copy per agent session is the failure mode.

### Environment

- **OS:** macOS (Darwin 24.6.0), APFS `/System/Volumes/Data`
- **Product:** Cursor IDE, Agent sandboxed terminal (not Legacy)
- **Cursor version:** _\<paste Help → About\>_
- **Workload:** large Cargo workspace (`cargo test` pulling `wasmtime-wasi` / `rocci-roc-host`)

### Related

- [Rust and sandboxing](https://forum.cursor.com/t/rust-and-sandboxing/150879) — `CARGO_HOME` / `RUSTUP_HOME` redirected into `cursor-sandbox-cache`
- [Shell tool injects 30+ sandbox cache env vars](https://forum.cursor.com/t/shell-tool-injects-30-sandbox-cache-environment-variables-even-with-required-permissions-all-breaking-build-tools/151772) — injection even with `all`
- [Playwright / empty sandbox cache](https://forum.cursor.com/t/agent-sandbox-redirects-playwright-browsers-path-and-npm-config-devdir-to-empty-cursor-sandbox-cache-windows-playwright-reinstall-loops-npm-11-warnings/167542) — `enableSharedBuildCache` opt-out broken
- Docs: [sandbox.json](https://cursor.com/docs/reference/sandbox.md), [Run Modes](https://cursor.com/docs/agent/security/run-modes)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea3.discourse-cdn.com/cursor1/user_avatar/forum.cursor.com/colin/32/90452_2.png) [@Colin](https://forum.cursor.com/u/Colin)\
**Post date:** [September 14, 2026, 9:09am UTC](https://forum.cursor.com/t/let-sandbox-json-pin-shared-build-caches-to-the-workspace-cargo-cargo-target-dir-not-hashed-cursor-sandbox-cache-dirs/171287/12 "2026-09-14T09:09:54Z")

</div>

Hey @koliyo, thanks for the feedback! There are a couple of workarounds you can try today, acknowledging that setting `enableSharedBuildCache` in the user-level `.cursor/sandbox.json` doesn’t currently work as expected.

**1. Per repo:** Add `.cursor/sandbox.json` at the workspace root with:

```json
{ "enableSharedBuildCache": false }

```

Sandboxed commands will then no longer have `CARGO_TARGET_DIR` (or the other cache variables) set, so cargo falls back to `.cargo/config.toml` / `./target`, just like in your own terminal. Note that this only applies to commands that actually run inside the sandbox (when the agent requests elevated permissions (network or full access), the command runs outside the sandbox and the redirect still applies). If other tools (npm, pip, Go) start complaining about writing their caches, add those cache folders to `additionalReadwritePaths` in the same file.

**2. Globally:** Export `CARGO_TARGET_DIR` in your login shell profile (for zsh, `~/.zshenv` or `~/.zprofile`), then fully quit and relaunch Cursor. Cursor picks up your shell environment on launch, and a variable set there takes precedence over the injected value in every agent shell, sandboxed or not. Keep the path inside the workspace (or in `additionalReadwritePaths`) so the sandbox can write to it.

Would love to know if either of these solves it for you for now.
