feat(ts-sdk): allow overriding CLI environment (#6648)

## Summary
- add an `env` option for the TypeScript Codex client and plumb it into
`CodexExec` so the CLI can run without inheriting `process.env`
- extend the test spy to capture spawn environments, add coverage for
the new option, and document how to use it

## Testing
- `pnpm test` *(fails: corepack cannot download pnpm because outbound
network access is blocked in the sandbox)*

------
[Codex
Task](https://chatgpt.com/codex/tasks/task_i_6916b2d7c7548322a72d61d91a2dac85)
This commit is contained in:
Ryan Lopopolo
2025-11-14 11:44:19 -08:00
committed by GitHub
parent 37fba28ac3
commit 936650001f
6 changed files with 88 additions and 6 deletions

View File

@@ -115,3 +115,19 @@ const thread = codex.startThread({
skipGitRepoCheck: true,
});
```
### Controlling the Codex CLI environment
By default, the Codex CLI inherits the Node.js process environment. Provide the optional `env` parameter when instantiating the
`Codex` client to fully control which variables the CLI receives—useful for sandboxed hosts like Electron apps.
```typescript
const codex = new Codex({
env: {
PATH: "/usr/local/bin",
},
});
```
The SDK still injects its required variables (such as `OPENAI_BASE_URL` and `CODEX_API_KEY`) on top of the environment you
provide.