Skip to content

Commit 7b61ef4

Browse files
dvdksnclaude
andcommitted
docs: add shell environment customization to kit examples
Show how to source a tool's init script as part of a kit, using SDKMAN! as a concrete example for version managers like sdkman and nvm. The primitives (install commands) already support this, but the pattern wasn't illustrated anywhere, which made it hard to answer questions about getting version managers working in a sandbox. Append to /etc/sandbox-persistent.sh — the sandbox's established persistent environment file, sourced for both interactive and non-interactive shells — to match the convention documented in the FAQ for custom environment variables. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 6e99480 commit 7b61ef4

1 file changed

Lines changed: 50 additions & 1 deletion

File tree

content/manuals/ai/sandboxes/customize/kit-examples.md

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Kit examples
33
linkTitle: Examples
4-
description: Copy-and-adapt spec.yaml snippets for common mixin and agent kit patterns — static files, install commands, background services, initFiles, Claude Code skills, and agent forks.
4+
description: Copy-and-adapt spec.yaml snippets for common mixin and agent kit patterns — static files, install commands, shell customization, background services, initFiles, Claude Code skills, and agent forks.
55
keywords: sandboxes, sbx, kits, mixins, examples, patterns, skills
66
weight: 25
77
---
@@ -72,6 +72,55 @@ step should run as the agent user — for example, `npm install -g`
7272
against a user-scoped prefix, or anything that writes to
7373
`/home/agent/`.
7474

75+
## Customize the shell environment
76+
77+
Some tools install into a versioned directory and expect you to source
78+
an init script from your shell profile so their commands land on `PATH`.
79+
Version managers like [SDKMAN!](https://sdkman.io/) and
80+
[nvm](https://github.com/nvm-sh/nvm) follow this pattern. To make the
81+
tool available in every shell, append the source line to
82+
`/etc/sandbox-persistent.sh` in an install command.
83+
84+
`/etc/sandbox-persistent.sh` is the sandbox's persistent environment
85+
file. It's sourced before every bash invocation — interactive shells and
86+
non-interactive ones, including agents started with `sbx run` and
87+
commands run with `sbx exec`. Appending here makes the tool available to
88+
the agent regardless of how its shell is launched. The same file is where
89+
you'd set a custom environment variable; see the
90+
[FAQ](../faq.md#how-do-i-set-custom-environment-variables-inside-a-sandbox).
91+
92+
```yaml {title="sdkman/spec.yaml"}
93+
schemaVersion: "1"
94+
kind: mixin
95+
name: sdkman
96+
displayName: SDKMAN!
97+
description: Java SDK manager available in every shell
98+
99+
commands:
100+
install:
101+
- command: "curl -fsSL https://get.sdkman.io | bash"
102+
user: "1000"
103+
description: Install SDKMAN!
104+
- command: |
105+
cat >> /etc/sandbox-persistent.sh <<'EOF'
106+
export SDKMAN_DIR="$HOME/.sdkman"
107+
[ -s "$SDKMAN_DIR/bin/sdkman-init.sh" ] && source "$SDKMAN_DIR/bin/sdkman-init.sh"
108+
EOF
109+
description: Source SDKMAN! for every shell
110+
```
111+
112+
The install step runs as `user: "1000"` so the tool lands under
113+
`/home/agent/`. The append step runs as root (the default), since
114+
`/etc/sandbox-persistent.sh` is a system file. The `$HOME` in the
115+
appended lines resolves per user at source time, so the agent user finds
116+
its own install. Append to the file rather than overwriting it —
117+
the sandbox relies on its existing contents.
118+
119+
Append only the init script, not the tool's tab-completion script.
120+
Because `/etc/sandbox-persistent.sh` is sourced before every command,
121+
completion scripts — which rely on variables that exist only during
122+
completion — can break non-interactive shells that agents rely on.
123+
75124
## Install an internal CA certificate
76125

77126
If your organization uses a proxy that inspects HTTPS traffic, install

0 commit comments

Comments
 (0)