|
1 | 1 | --- |
2 | 2 | title: Kit examples |
3 | 3 | 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. |
5 | 5 | keywords: sandboxes, sbx, kits, mixins, examples, patterns, skills |
6 | 6 | weight: 25 |
7 | 7 | --- |
@@ -72,6 +72,55 @@ step should run as the agent user — for example, `npm install -g` |
72 | 72 | against a user-scoped prefix, or anything that writes to |
73 | 73 | `/home/agent/`. |
74 | 74 |
|
| 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 | + |
75 | 124 | ## Install an internal CA certificate |
76 | 125 |
|
77 | 126 | If your organization uses a proxy that inspects HTTPS traffic, install |
|
0 commit comments