//go:build linux package containment import ( "amadan.net/oficina/equipo/internal/runner/provider" "amadan.net/oficina/equipo/internal/runner/provider/claude" "amadan.net/oficina/equipo/internal/runner/provider/codex" "encoding/json" "fmt" "io" "testing" ) // Claude has no offline entry point for its bundled sandbox builder. This // reproduction consumes the generated filesystem settings and its pinned // defaults: cwd and CLAUDE_CODE_TMPDIR/claude-${uid}, never all of /tmp. // Codex exposes `sandbox`, so that branch invokes the real pinned executable. func engineeringShell(t *testing.T, name, body string) string { t.Helper() b := provider.Binding{Provider: name, Home: "/fake-runtime", CredentialHome: "/fake-source", RuntimeRoot: "/fake-homes"} profile, _ := provider.Profile("implement") in := provider.PolicyInputs{Action: "implement", Tools: profile.MCPTools()} var err error if name == "claude" { in, err = claude.PolicyInputs(b, in, "Engineering", "claude-opus-5-5") } else { in, err = codex.PolicyInputs(b, in, "gpt-6-luna") } if err != nil { t.Fatal(err) } settings, _ := json.Marshal(string(in.Settings)) script, _ := json.Marshal(body) return fmt.Sprintf(`import json,os,subprocess settings=json.loads(%s) if %q=='claude': s=settings['sandbox']; fs=s['filesystem'] assert s['enabled'] and s['failIfUnavailable'] and not s['allowUnsandboxedCommands'] and not s.get('enableWeakerNestedSandbox',False) temp=os.path.join(os.environ.get('CLAUDE_CODE_TMPDIR','/tmp'),'claude-'+str(os.getuid())) os.makedirs(temp,exist_ok=True) prefix=['/opt/bwrap','--new-session','--die-with-parent','--unshare-net','--ro-bind','/','/'] for path in [os.getcwd(),temp]+fs.get('allowWrite',[]): prefix+=['--bind',path,path] for path in fs['denyRead']: if os.path.isdir(path) and path not in ['/proc','/dev/fd']: prefix+=['--tmpfs',path,'--remount-ro',path] for path in fs['denyWrite']: if os.path.isdir(path) and path not in fs['denyRead']: prefix+=['--ro-bind',path,path] for path in ['/workspace/.git/config','/workspace/.git/hooks']: if os.path.exists(path): prefix+=['--ro-bind',path,path] prefix+=['--dev','/dev','--unshare-pid','--unshare-user','--proc','/proc','--disable-userns','--'] else: p=settings['permissions']['equipo'] fs=','.join(json.dumps(k)+'='+json.dumps(v) for k,v in sorted(p['filesystem'].items())) prefix=['/opt/codex','sandbox','-P','equipo','-C','/workspace','-c','permissions.equipo.filesystem={'+fs+'}','-c','permissions.equipo.network.enabled='+str(p['network']['enabled']).lower(),'--'] child={k:v for k,v in os.environ.items() if k!='CLAUDE_CODE_OAUTH_TOKEN'} r=subprocess.run(prefix+['/usr/bin/python3','-c',%s],env=child,capture_output=True,text=True) print(r.stdout,flush=True) assert r.returncode==0,(r.returncode,r.stderr) `, settings, name, script) } func engineeringOutput(p provider.Process) ([]byte, []byte) { stderr := make(chan []byte, 1) go func() { raw, _ := io.ReadAll(p.Stderr()); stderr <- raw }() stdout, _ := io.ReadAll(p.Stdout()) return stdout, <-stderr }