Repository navigation
Add a universal environment guide for Sandbox agents #135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
thebrandonlucas
wants to merge
2
commits into
main
Choose a base branch
from
aurelius/sandbox-environment-guide
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
|
|
||
| ## Working in the Sandbox | ||
|
|
||
| Before you say you lack access to a service, run `via capabilities` and `buzz --help`. | ||
| Enrolled services (for example Linear, Grafana and Argo CD) are reached with the capability that `via capabilities` lists for the service, usually `via <service> api ...`, not with a dedicated CLI or an environment variable. | ||
| Depot is different: the image wires it into build caches (for example `depot gocache`), so it has no `via depot api`; check the cache before calling it unavailable. | ||
| When you report that something is unavailable, say which places you checked. | ||
|
|
||
| Check that you are in a Sandbox with `KUBERNETES_SERVICE_HOST`, not with the path `/var/run/secrets/kubernetes.io`, which is not mounted in this Pod. | ||
|
thebrandonlucas marked this conversation as resolved.
Resolved
|
||
|
|
||
| A service reached through `via` may act as its own app identity or as a user, depending on how it is configured. | ||
| When you report a change made through it, such as a ticket you created, name the identity it used, or say that you do not know. | ||
|
|
||
| This Pod holds live credentials: a cluster token, your Buzz key, and `via` access. | ||
| Do not build, test, install dependencies for, or run code from a repository you do not trust. | ||
| Read its source, or ask the person you work for first. | ||
|
|
||
| Keep details of an unfixed vulnerability out of public issues, pull requests, commit messages and public channels. | ||
| Report them only where the person you work for has chosen, such as a private channel or the company tracker. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| """Check that every session receives the environment guide, with or without cluster credentials.""" | ||
| import subprocess | ||
| import sys | ||
|
|
||
| SCRIPT = r''' | ||
| import os, runpy, sys, tempfile | ||
| from pathlib import Path | ||
|
|
||
| profile = runpy.run_path('/usr/local/bin/buzz-agent-profile', run_name='probe') | ||
| install = profile['install_environment_guide'] | ||
| settings = install.__globals__ | ||
| home = Path(tempfile.mkdtemp(prefix='environment-test-', dir='/home/agent')) | ||
| claude = Path('/home/agent/.claude/CLAUDE.md') | ||
|
|
||
| def require(condition, message): | ||
| if not condition: raise RuntimeError(message) | ||
|
|
||
| guide = settings['ENVIRONMENT_GUIDE'].read_text() | ||
| require('via capabilities' in guide and 'KUBERNETES_SERVICE_HOST' in guide, 'guide lost its rules') | ||
| settings['CLUSTER_CREDENTIALS'] = home / 'no-worker' | ||
| settings['SUBAGENT_CREDENTIALS'] = home / 'no-primary' | ||
| claude.parent.mkdir(parents=True, exist_ok=True) | ||
| claude.write_text('existing instructions\n') | ||
| env = {**os.environ, 'CODEX_HOME': str(home / 'codex')} | ||
| install(env) | ||
| install(env) | ||
|
thebrandonlucas marked this conversation as resolved.
Resolved
|
||
| require(claude.read_text().startswith('existing instructions\n' + guide), 'Claude Code instructions were replaced or lack the guide') | ||
| require(claude.read_text().count('## Working in the Sandbox') == 2, 'each install call should append the guide once') | ||
| require((home / 'codex/AGENTS.md').read_text() == guide * 2, 'Codex instructions lack the guide') | ||
|
|
||
| # Bind the production seam: each startup path must install the guide before it launches its child. | ||
| main = settings['main'] | ||
| for action in ('run', 'work'): | ||
| claude.write_text('') | ||
| events = [] | ||
| class Launched(Exception): pass | ||
| def launch(path, argv, env): events.append('launch'); raise Launched() | ||
| settings.update( | ||
| step=lambda message: None, bootstrap=lambda: env, restore_checkpoint=lambda: None, | ||
| install_cluster_access=lambda env: None, install_subagent_guide=lambda env: None, | ||
| install_skills=lambda env: None, | ||
| install_environment_guide=lambda env, real=install: (events.append('guide'), real(env))) | ||
| settings['os'].execvpe = launch | ||
| sys.argv = ['profile', action] | ||
| try: main() | ||
| except Launched: pass | ||
| require(events == ['guide', 'launch'], action + ' did not install the guide before launching: ' + repr(events)) | ||
| require(claude.read_text() == guide, action + ' did not write the guide') | ||
| print('PASS: the guide reaches Claude Code and Codex, and both startup paths install it') | ||
| ''' | ||
|
|
||
| if __name__ == '__main__': | ||
| result = subprocess.run(['docker', 'run', '--rm', '-i', '--network', 'none', | ||
| '--entrypoint', 'python3', sys.argv[1] if len(sys.argv) > 1 else 'buzz-agent:local', '-'], | ||
| input=SCRIPT, text=True, timeout=90) | ||
| raise SystemExit(result.returncode) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.