Skip to content

Add Docker sandbox for isolated agent execution#12

Merged
AaronGoldsmith merged 3 commits intomainfrom
feature/docker-sandbox
Mar 21, 2026
Merged

Add Docker sandbox for isolated agent execution#12
AaronGoldsmith merged 3 commits intomainfrom
feature/docker-sandbox

Conversation

@AaronGoldsmith
Copy link
Copy Markdown
Owner

Summary

  • Agents run inside disposable python:3.12-slim containers (no network, 512MB limit)
  • Enable with mobius run --sandbox or MOBIUS_SANDBOX=true
  • Bind-mounts working directory to /workspace in container
  • Public get_current_sandbox() API for sandbox state

Review fixes addressed

  • Check docker start return code, cleanup on failure
  • Fail closed when sandbox unavailable (no silent host fallback)
  • Use sh -lc instead of bash -c for slim image compat
  • Bind-mount working_dir into container at /workspace
  • Public getter instead of importing private _current_sandbox

Split from PR #10

Test plan

  • pytest tests/ -v
  • mobius run --sandbox "hello world" creates and destroys container
  • Verify no host fallback when sandbox is missing

🤖 Generated with Claude Code

Adds container lifecycle management (create/destroy/set sandbox),
sandbox-aware command routing, and CLI --sandbox flag. Includes
review fixes: bind-mount working_dir, check docker start return
code, fail closed on missing sandbox, use sh -lc for compatibility,
expose get_current_sandbox() public getter.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 21, 2026 16:18
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces an optional Docker-based sandbox to run agent shell-tool execution in an isolated, disposable container, and updates agent environment context to reflect sandboxed execution.

Changes:

  • Add sandbox container lifecycle helpers (create_sandbox, destroy_sandbox) and route tool command execution through docker exec when sandbox is active.
  • Add CLI/config toggles to enable sandbox mode (--sandbox, MOBIUS_SANDBOX=true) and configure the image.
  • Update agent environment context prefix to report /workspace and Linux container platform when sandboxed.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/mobius/providers/tools.py Adds sandbox lifecycle + routes run_command through Docker exec when sandbox is set.
src/mobius/orchestrator.py Creates/sets sandbox for a competition and tears it down afterward.
src/mobius/config.py Introduces sandbox config fields and env var parsing for enabling/image override.
src/mobius/cli.py Adds --sandbox flag to enable sandbox mode from the CLI.
src/mobius/runner.py Adjusts environment context shown to agents when sandbox is active.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/mobius/orchestrator.py Outdated
Comment thread src/mobius/providers/tools.py Outdated
…code

- orchestrator.py: Raise RuntimeError when sandbox creation fails and
  sandbox_enabled=True instead of silently falling back to host execution
- providers/tools.py: Check docker rm returncode before removing from
  _active_containers dict; only clean up tracking on success

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@AaronGoldsmith AaronGoldsmith marked this pull request as ready for review March 21, 2026 17:08
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

live_ctx = ui.start() if ui else None

P2 Badge Start UI inside cleanup guard

Sandbox teardown only happens in the finally block that starts after live_ctx = ui.start(). If SwarmUI() or ui.start() raises (for example in a non-interactive terminal), control exits before the finally, leaving _current_sandbox set and the Docker container undeleted. In long-lived processes (e.g., repeated competitions in one process), this leaks containers and can route later tool calls to a stale sandbox.

ℹ️ 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 src/mobius/orchestrator.py
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@AaronGoldsmith AaronGoldsmith merged commit 7cf1988 into main Mar 21, 2026
2 checks passed
@AaronGoldsmith AaronGoldsmith deleted the feature/docker-sandbox branch March 21, 2026 17:31
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.

2 participants