Skip to content

perf: Add brokered nsjail Claude runtime#2468

Merged
daryllimyt merged 31 commits intomainfrom
perf/sandbox-2
Apr 22, 2026
Merged

perf: Add brokered nsjail Claude runtime#2468
daryllimyt merged 31 commits intomainfrom
perf/sandbox-2

Conversation

@daryllimyt
Copy link
Copy Markdown
Contributor

@daryllimyt daryllimyt commented Apr 3, 2026

Summary

  • add a worker-global brokered Claude runtime path for sandboxed agent execution
  • fix the brokered nsjail integration details needed for stable resume, shim startup, stderr reporting, and bundled CLI execution
  • simplify the loopback and activity flow on top of the working broker implementation

Testing

  • uv run pytest tests/unit/test_agent_executor_loopback.py tests/unit/test_agent_runtime.py tests/unit/test_agent_runtime_services.py tests/unit/test_agent_runtime_broker.py tests/unit/test_agent_sandbox_entrypoint.py tests/unit/test_agent_sandbox_config.py -q
  • uv run ruff check tracecat/agent/executor/activity.py tracecat/agent/executor/loopback.py tracecat/agent/runtime/claude_code/broker.py tracecat/agent/sandbox/shim_entrypoint.py tests/unit/test_agent_executor_loopback.py
  • uv run pyright tracecat/agent/executor/activity.py tracecat/agent/executor/loopback.py tracecat/agent/runtime/claude_code/broker.py tracecat/agent/runtime/claude_code/transport.py tracecat/agent/sandbox/shim_entrypoint.py tests/unit/test_agent_executor_loopback.py tests/unit/test_agent_runtime.py tests/unit/test_agent_runtime_broker.py tests/unit/test_agent_sandbox_entrypoint.py tests/unit/test_agent_sandbox_config.py

Summary by cubic

Adds a worker‑global, brokered Claude runtime via a standalone nsjail shim as the only execution path. Startup and shutdown are faster and more reliable with a unified, size‑capped init payload, non‑blocking shim stdin handling, stable per‑session paths, correct transport mode handling, and durable workflows routed through the executor with session control across approval continuation.

  • New Features

    • Broker-managed runtime with concurrent‑turn protection; launches Claude Code via SandboxedCLITransport using orjson for faster I/O.
    • Single sandbox entrypoint: stdlib‑only shim derives mode from its path and requires an init payload path for both direct and nsjail modes; fixed LLM socket path.
    • Executor worker and runtime services start/stop the broker; durable workflow runs through the agent executor and preserves forked sessions across approvals.
  • Refactors

    • Removed internal LLM proxy lifecycle and legacy HTTP path; ClaudeAgentRuntime now requires a transport_factory.
    • Loopback no longer sends init and initializes the stream sink lazily; removed a duplicate event processor; preserves error state on completion.
    • More robust startup/cleanup: cap init payload size, avoid process‑wide umask on control sockets, close leaked control server on failure, clean spawned state, mount explicit Claude session dirs, reduce shim mounts, preserve direct‑mode importability, and avoid blocking shim shutdown on stdin.

Written for commit f415523. Summary will update on new commits.

@daryllimyt daryllimyt temporarily deployed to internal-registry-ci April 3, 2026 02:55 — with GitHub Actions Inactive
@daryllimyt daryllimyt temporarily deployed to internal-registry-ci April 3, 2026 02:55 — with GitHub Actions Inactive
@zeropath-ai
Copy link
Copy Markdown

zeropath-ai Bot commented Apr 3, 2026

No security or compliance issues detected. Reviewed everything up to f415523.

Security Overview
Detected Code Changes

The diff is too large to display a summary of code changes.

@daryllimyt daryllimyt marked this pull request as ready for review April 3, 2026 03:09
@daryllimyt daryllimyt temporarily deployed to internal-registry-ci April 3, 2026 03:13 — with GitHub Actions Inactive
@daryllimyt daryllimyt temporarily deployed to internal-registry-ci April 3, 2026 03:13 — with GitHub Actions Inactive
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4 issues found across 22 files

Confidence score: 2/5

  • There is a high-confidence race in tracecat/agent/runtime/claude_code/broker.py where run_turn() may create a new session after stop() sets _closed, which can lead to inconsistent lifecycle state and hard-to-reproduce runtime failures.
  • docker-compose.dev.yml introduces broad privileges (SYS_ADMIN, seccomp:unconfined, /dev/net/tun) for agent-executor unconditionally, which is a meaningful security-risk increase even in a dev profile.
  • Additional medium-severity reliability issues in tracecat/agent/sandbox/shim_entrypoint.py (stdin broken pipe/reset handling) and tracecat/agent/runtime/claude_code/transport.py (path resolution mismatch skipping jail rewrite) raise concrete regression risk in process execution flows.
  • Pay close attention to tracecat/agent/runtime/claude_code/broker.py, docker-compose.dev.yml, tracecat/agent/sandbox/shim_entrypoint.py, tracecat/agent/runtime/claude_code/transport.py - fix lifecycle race, privilege escalation defaults, stdin-forwarding robustness, and executable path normalization before merge.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="tracecat/agent/sandbox/shim_entrypoint.py">

<violation number="1" location="tracecat/agent/sandbox/shim_entrypoint.py:124">
P2: Handle broken pipe/reset while forwarding stdin so early child stdin closure doesn't crash the shim.</violation>
</file>

<file name="tracecat/agent/runtime/claude_code/transport.py">

<violation number="1" location="tracecat/agent/runtime/claude_code/transport.py:274">
P2: Resolve `executable` for consistent comparison with the resolved `host_site_packages_root`. Without this, symlinked venvs or CLI paths will silently skip the jail rewrite, and the subprocess will fail to find the CLI binary inside the sandbox.</violation>
</file>

<file name="docker-compose.dev.yml">

<violation number="1" location="docker-compose.dev.yml:295">
P1: `agent-executor` now runs with `SYS_ADMIN` + `seccomp:unconfined` + `/dev/net/tun` unconditionally, which grants broad host-level privileges even when nsjail remains disabled by default.</violation>
</file>

<file name="tracecat/agent/runtime/claude_code/broker.py">

<violation number="1" location="tracecat/agent/runtime/claude_code/broker.py:52">
P1: `run_turn()` can start a new session after `stop()` sets `_closed` due to a check-then-lock race. Re-check `_closed` inside the locked section before registering `_active_turns`.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread docker-compose.dev.yml Outdated
Comment thread tracecat/agent/runtime/claude_code/broker.py
Comment thread tracecat/agent/sandbox/shim_entrypoint.py Outdated
Comment thread tracecat/agent/runtime/claude_code/transport.py Outdated
@daryllimyt daryllimyt temporarily deployed to internal-registry-ci April 3, 2026 17:36 — with GitHub Actions Inactive
@daryllimyt daryllimyt temporarily deployed to internal-registry-ci April 3, 2026 17:37 — with GitHub Actions Inactive
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 4 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="tracecat/agent/sandbox/shim_entrypoint.py">

<violation number="1" location="tracecat/agent/sandbox/shim_entrypoint.py:299">
P2: Use `os.environ.get(VAR) or DEFAULT` instead of `os.environ.get(VAR, DEFAULT)` so an empty-string env var falls back to the default rather than creating `Path("")` (which resolves to cwd).

(Based on your team's feedback about using the `or` fallback pattern for env vars before type conversion.) [FEEDBACK_USED]</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread tracecat/agent/sandbox/shim_entrypoint.py Outdated
@daryllimyt daryllimyt temporarily deployed to internal-registry-ci April 3, 2026 19:00 — with GitHub Actions Inactive
@daryllimyt daryllimyt temporarily deployed to internal-registry-ci April 3, 2026 19:01 — with GitHub Actions Inactive
@daryllimyt daryllimyt requested a review from jordan-umusu April 9, 2026 18:03
@daryllimyt daryllimyt temporarily deployed to internal-registry-ci April 20, 2026 21:25 — with GitHub Actions Inactive
@daryllimyt daryllimyt temporarily deployed to internal-registry-ci April 20, 2026 21:25 — with GitHub Actions Inactive
@blacksmith-sh

This comment has been minimized.

@daryllimyt daryllimyt temporarily deployed to internal-registry-ci April 20, 2026 23:16 — with GitHub Actions Inactive
@daryllimyt daryllimyt temporarily deployed to internal-registry-ci April 20, 2026 23:16 — with GitHub Actions Inactive
@daryllimyt daryllimyt temporarily deployed to internal-registry-ci April 21, 2026 00:55 — with GitHub Actions Inactive
@daryllimyt daryllimyt temporarily deployed to internal-registry-ci April 21, 2026 00:55 — with GitHub Actions Inactive
@daryllimyt daryllimyt temporarily deployed to internal-registry-ci April 21, 2026 02:53 — with GitHub Actions Inactive
@daryllimyt daryllimyt had a problem deploying to internal-registry-ci April 21, 2026 02:54 — with GitHub Actions Failure
@blacksmith-sh

This comment has been minimized.

@daryllimyt daryllimyt temporarily deployed to internal-registry-ci April 21, 2026 03:14 — with GitHub Actions Inactive
@daryllimyt daryllimyt temporarily deployed to internal-registry-ci April 21, 2026 03:15 — with GitHub Actions Inactive
@daryllimyt daryllimyt temporarily deployed to internal-registry-ci April 21, 2026 03:47 — with GitHub Actions Inactive
@daryllimyt daryllimyt had a problem deploying to internal-registry-ci April 21, 2026 03:47 — with GitHub Actions Failure
@daryllimyt daryllimyt changed the title Add brokered nsjail Claude runtime perf: Add brokered nsjail Claude runtime Apr 21, 2026
LiteLLM is managed externally, so start_configured_llm_proxy and
stop_configured_llm_proxy were pure ceremony with no actual work.
The transport factory was optional to support a legacy HTTP path that
is no longer used in production. Making it required simplifies the
runtime by removing conditional env var logic for ANTHROPIC_BASE_URL
and HOME, both of which are now handled exclusively by the transport.
@daryllimyt daryllimyt temporarily deployed to internal-registry-ci April 21, 2026 19:51 — with GitHub Actions Inactive
@daryllimyt daryllimyt temporarily deployed to internal-registry-ci April 21, 2026 19:51 — with GitHub Actions Inactive
@daryllimyt daryllimyt temporarily deployed to internal-registry-ci April 21, 2026 20:50 — with GitHub Actions Inactive
@daryllimyt daryllimyt temporarily deployed to internal-registry-ci April 21, 2026 20:51 — with GitHub Actions Inactive
@daryllimyt daryllimyt temporarily deployed to internal-registry-ci April 21, 2026 21:28 — with GitHub Actions Inactive
@cubic-dev-ai
Copy link
Copy Markdown
Contributor

cubic-dev-ai Bot commented Apr 21, 2026

You're iterating quickly on this pull request. To help protect your rate limits, cubic has paused automatic reviews on new pushes for now—when you're ready for another review, comment @cubic-dev-ai review.

@daryllimyt daryllimyt temporarily deployed to internal-registry-ci April 21, 2026 21:28 — with GitHub Actions Inactive
@daryllimyt
Copy link
Copy Markdown
Contributor Author

@cubic-dev-ai review

@daryllimyt
Copy link
Copy Markdown
Contributor Author

@codex review

@cubic-dev-ai
Copy link
Copy Markdown
Contributor

cubic-dev-ai Bot commented Apr 21, 2026

@cubic-dev-ai review

@daryllimyt I have started the AI code review. It will take a few minutes to complete.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fc96e0a206

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tracecat/agent/sandbox/shim_entrypoint.py Outdated
Comment thread tracecat/agent/executor/loopback.py
@daryllimyt daryllimyt temporarily deployed to internal-registry-ci April 22, 2026 01:30 — with GitHub Actions Inactive
@daryllimyt daryllimyt temporarily deployed to internal-registry-ci April 22, 2026 01:30 — with GitHub Actions Inactive
@daryllimyt daryllimyt merged commit 02a8546 into main Apr 22, 2026
16 checks passed
@daryllimyt daryllimyt deleted the perf/sandbox-2 branch April 22, 2026 02:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant