mirror of
https://github.com/kvcache-ai/AgentENV.git
synced 2026-11-05 01:17:36 +00:00
[PR #309] [MERGED] feat: add native Codex sessions to aenv CLI #336
Labels
No labels
bug
documentation
enhancement
enhancement
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
kvcache-ai/AgentENV#336
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/kvcache-ai/AgentENV/pull/309
Author: @Primary33
Created: 9/21/2026
Status: ✅ Merged
Merged: 9/24/2026
Merged by: @yingdi-shan
Base:
main← Head:docs/agentenv-codex-harness📝 Commits (2)
7961162feat(aenv): add native Codex sandbox sessions56897dddocs(aenv): document Codex sandbox workflow📊 Changes
17 files changed (+3133 additions, -3 deletions)
View changed files
📝
Cargo.lock(+3 -0)📝
crates/aenv/Cargo.toml(+4 -1)📝
crates/aenv/src/client/mod.rs(+4 -0)📝
crates/aenv/src/client/sandboxes.rs(+2 -0)📝
crates/aenv/src/commands/build.rs(+22 -0)➕
crates/aenv/src/commands/codex/assets/Dockerfile(+18 -0)➕
crates/aenv/src/commands/codex/guest.rs(+714 -0)➕
crates/aenv/src/commands/codex/mod.rs(+115 -0)➕
crates/aenv/src/commands/codex/project.rs(+536 -0)➕
crates/aenv/src/commands/codex/runtime.rs(+1013 -0)➕
crates/aenv/src/commands/codex/socket.rs(+556 -0)📝
crates/aenv/src/commands/download.rs(+1 -1)📝
crates/aenv/src/commands/mod.rs(+1 -0)📝
crates/aenv/src/main.rs(+3 -0)📝
docs/src/SUMMARY.md(+1 -0)📝
docs/src/getting-started/aenv-cli/index.md(+2 -1)➕
docs/src/use-cases/codex.md(+138 -0)📄 Description
What
Add
aenv codex setup,start,resume, andfinishso users can work on their projects through the native Codex terminal with execution in an AgentENV sandbox.Why
Users should be able to start a sandbox coding session from the installed CLI. Template assets and connection logic ship in
aenv; no repository checkout, separate launcher, or Python runtime is needed for the integration.Related issue
None.
Scope and non-goals
The interactive aenv command, bundled executor template, project transfer and session lifecycle, and a Use Cases guide. Server APIs and storage formats are unchanged.
Design and behavior changes
setupprepares the embedded executor template through the existing aenv builder and saves only its name. It does not require a local Codex installation;startandresumecheck the local version. Later sessions reuse the template.start <project>uploads working files, then opens the unmodified Codex CLI. The host app-server uses the user's native Codex configuration and authentication. A process-local executor URL connects it to the sandbox with local execution disabled; no model credentials are copied into aenv settings or the guest./diffreads sandbox files. The executor and workspace service connect through authenticated AgentENV proxy connections; model credentials stay on the host./quitstops active work, saves a project copy and patch, and pauses the sandbox.resumerestores the sandbox and conversation.finishsaves before deletion;recoveris an alias.finishpersists adeletion-pendingstate before sending DELETE. Repeatingfinishretries deletion without reconnecting or exporting again, accepts an already-deleted sandbox, and completes the final local status update. Errors retain the saved path and recovery instructions;resumerejects sessions whose deletion has started.finishshare the save/cleanup path. Downloads reuse the existing CLI stream writer. Conversation history is stored by Codex;thread-idis the sole conversation ID record and is rewritten only when the ID changes. The wrapper caches thread eligibility rather than complete thread objects and does not record completed results or write a duplicate event journal./procsnapshot, so PID/PGID reuse cannot redirect cleanup to an unrelated group. Process snapshots only determine when shutdown has finished. File export uses a validated NUL-delimited Git file list and system tar; no Python helper scripts are shipped or invoked.Compatibility and operations
startandresumeneed an interactive terminal. Node.js is needed for npm installation of Codex. The template still includes Python for user project tasks; the integration does not depend on it. First-time template builds use the existingaenv-buildctlinstalled besideaenv.~/.codexorCODEX_HOME, including its configured credential store and provider environment variables.aenvstores only the template name in~/.config/aenv/codex.json; it neither prompts for nor copies model credentials.--modelremains a temporary native Codex override. Sessions default to~/.local/share/aenv/codex/sessions/; XDG directories are honored. Resume with the same Codex home.finishwhen done. Lease expiry auto-pauses a sandbox after abrupt launcher termination.Validation
The checks above were run as a non-root user on the existing Linux test host for the deletion-recovery fix. Four new regression tests cover failed DELETE retries (including authorization errors), a lost DELETE response, a failed post-delete manifest write, and refusing deletion when the pending state cannot be persisted. They use local mock HTTP endpoints; the live sandbox/model workflow was not rerun for this fix.
Earlier live checks on a Linux AgentENV deployment, running the compiled binary outside the source tree. The previous cleanup validation rechecked cleanup, export failure, and recovery; the other feature checks below preceded that cleanup change:
pythonnorpython3installed: read a random value present only inside the sandbox, edit files, inspect/diff, exit with saved files, and resume the same conversation for another edit.finishsaved results and deleted the sandbox.finishrecovered the work after the export issue was corrected./diff, and failed-export recovery. Recovery works without model credentials, and repeatedfinishis safe. Non-terminal start/resume is rejected before creating or connecting a sandbox.pythonnorpython3: an envd-tagged supervisor without a persisted record was recovered, TERM-ignoring descendants were stopped, and a stale record naming an unrelated group left that group running. An unsafe export retained the sandbox; correcting the export allowedfinishto save and delete it.codex login --with-api-key) and custom providerenv_keyauthentication both completed interactive sandbox tasks,/diff, saving and resume. Two overlapping sessions reused one native Codex home with separate sandbox files and conversations. Setup worked without any model configuration or credentials. Provider settings were preserved; native Codex recorded its own project trust setting.tui.alternate_screen = "always", the model followed the configured instructions and the native UI entered and restored the alternate screen. Sandbox-only file access,/diff, saving, resume with a follow-up task, andfinishall passed. Start/resume help no longer exposes a wrapper turn timeout.thread-iddespite a stale legacy ID insession.json, and unchanged IDs retained the same file inode across resume and follow-up turns. Killing the owned launcher process group with SIGKILL still allowed the same sandbox and conversation to resume;finishthen saved and deleted the test sandbox.environments.tomlwas rejected before a sandbox or session was created. Template setup discarded legacy model fields without migrating credentials.Server, storage, and Go suites were skipped because those components are unchanged.
Risks and reviewer notes
Codex 0.155.1 prioritizes
environments.tomlover the per-process sandbox URL. The launcher rejects that configuration without changing the file; users can configure a separate native Codex home. Earlier draft model fields are ignored and removed on the nextsetup. Conversation history in an earlier draft's private session home is not automatically migrated:finishcan save that project, thenstartopens it under native Codex configuration.Codex 0.155.1's native
@picker searches the CLI machine even in remote mode. The guide tells users to type relative sandbox paths instead; model file access and native/diffwork against the sandbox.Shutdown requires the service supervisor to remain available. Services from earlier drafts without supervisors, or services whose supervisors were externally killed, are retained for manual cleanup if live group members remain. The CLI refuses unsafe PID-based fallback. This uses the existing Bash/envd facilities and works with the default Linux 6.1 guest; no template rebuild or new runtime dependency is required.
Model commands run with automatic approval inside the sandbox. Review
commands/codex/runtime.rsfor lifecycle and recovery,guest.rsfor sandbox process ownership and cleanup,socket.rsfor RPC boundaries, andproject.rsfor file transfer checks.Checklist
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.