Conversation
When CONTAINER_PERSIST is set to 'true', containers are:
- Named deterministically (seclab-persist-{image-slug}) instead of randomly
- Started without --rm so they survive MCP server process exit
- Reused if already running (new MCP server attaches to existing container)
- Not stopped on atexit (container persists for the next task)
This enables multi-task taskflows to share state across tasks without
rebuilding the environment each time. Set CONTAINER_PERSIST in the
taskflow env or toolbox YAML to enable.
All container_shell toolbox YAMLs updated to expose CONTAINER_PERSIST.
There was a problem hiding this comment.
Pull request overview
Adds an opt-in “persistent container” mode for the container_shell MCP server so that a deterministic container can be reused across tasks, enabling shared state in multi-task taskflows.
Changes:
- Introduces
CONTAINER_PERSISTenv var (parsed as a boolean) and persistent lifecycle behavior incontainer_shell.py. - Adds
CONTAINER_PERSISTpassthrough to the container shell toolbox YAMLs (base/sast/network/malware).
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/seclab_taskflows/mcp_servers/container_shell.py | Adds deterministic naming + reuse logic and skips shutdown for persistent containers. |
| src/seclab_taskflows/toolboxes/container_shell_base.yaml | Passes CONTAINER_PERSIST into the MCP server environment. |
| src/seclab_taskflows/toolboxes/container_shell_sast.yaml | Passes CONTAINER_PERSIST into the MCP server environment. |
| src/seclab_taskflows/toolboxes/container_shell_network_analysis.yaml | Passes CONTAINER_PERSIST into the MCP server environment. |
| src/seclab_taskflows/toolboxes/container_shell_malware_analysis.yaml | Passes CONTAINER_PERSIST into the MCP server environment. |
Comments suppressed due to low confidence (1)
src/seclab_taskflows/mcp_servers/container_shell.py:47
docker inspectis invoked without a timeout. If the Docker daemon is unresponsive, this can block the MCP server indefinitely. Please add a reasonable timeout (consistent with thedocker runtimeout) and handlesubprocess.TimeoutExpiredso the tool fails fast with a clear error.
result = subprocess.run(
["docker", "inspect", "-f", "{{.State.Running}}", name],
capture_output=True,
text=True,
)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
- Use sha256 hash of full image ref (+ optional CONTAINER_PERSIST_KEY) for deterministic container names, avoiding collisions on long prefixes - Add timeouts to all docker subprocess calls (_DOCKER_TIMEOUT = 30s) - Extract _remove_container() helper with failure logging - Use docker inspect --format json + json.loads for _is_running() - Handle TimeoutExpired and JSONDecodeError gracefully - Add CONTAINER_PERSIST_KEY env var to all toolbox YAMLs - Add 11 tests covering persistent container behavior: name hashing, reuse, no --rm flag, stop skip, error logging
2854cad to
b646bea
Compare
There was a problem hiding this comment.
Pull request overview
This PR adds an opt-in “persistent container” mode to the container_shell MCP server so multi-task taskflows can reuse a deterministic, long-lived Docker container across server restarts.
Changes:
- Add
CONTAINER_PERSIST/CONTAINER_PERSIST_KEYsupport and deterministic container naming tocontainer_shell. - Add helper functions for checking container running state and removing leftovers.
- Extend toolbox YAMLs and add unit tests covering persistence behavior.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
src/seclab_taskflows/mcp_servers/container_shell.py |
Implements deterministic naming + reuse logic for persistent containers. |
tests/test_container_shell.py |
Adds unit tests for persistent naming, reuse, stop-skip behavior, and helper error paths. |
src/seclab_taskflows/toolboxes/container_shell_base.yaml |
Wires persistence env vars into the base container toolbox. |
src/seclab_taskflows/toolboxes/container_shell_malware_analysis.yaml |
Wires persistence env vars into the malware analysis toolbox. |
src/seclab_taskflows/toolboxes/container_shell_network_analysis.yaml |
Wires persistence env vars into the network analysis toolbox. |
src/seclab_taskflows/toolboxes/container_shell_sast.yaml |
Wires persistence env vars into the SAST toolbox. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
- docker rm without -f to avoid killing running containers on transient failures - use _DOCKER_TIMEOUT constant for docker run - assert full docker inspect argv in reuse test
There was a problem hiding this comment.
Pull request overview
Adds support for reusing a deterministic, persistent Docker container across MCP server runs in container_shell, controlled via new environment variables and propagated through the relevant toolboxes.
Changes:
- Introduces
CONTAINER_PERSIST/CONTAINER_PERSIST_KEYto enable deterministic container naming and reuse. - Updates container lifecycle logic to reuse running persistent containers and skip stopping them on exit.
- Adds unit tests for persistent naming, reuse behavior, and helper functions; updates toolboxes to pass through the new env vars.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
src/seclab_taskflows/mcp_servers/container_shell.py |
Implements persistent container naming, reuse checks, and adjusted stop/remove behavior. |
tests/test_container_shell.py |
Adds test coverage for persistent naming/reuse and helper behaviors. |
src/seclab_taskflows/toolboxes/container_shell_base.yaml |
Passes through CONTAINER_PERSIST and CONTAINER_PERSIST_KEY to the MCP server. |
src/seclab_taskflows/toolboxes/container_shell_malware_analysis.yaml |
Passes through CONTAINER_PERSIST and CONTAINER_PERSIST_KEY to the MCP server. |
src/seclab_taskflows/toolboxes/container_shell_network_analysis.yaml |
Passes through CONTAINER_PERSIST and CONTAINER_PERSIST_KEY to the MCP server. |
src/seclab_taskflows/toolboxes/container_shell_sast.yaml |
Passes through CONTAINER_PERSIST and CONTAINER_PERSIST_KEY to the MCP server. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Adds
CONTAINER_PERSISTenv var to container_shell. When set totrue, containers get a deterministic name, survive MCP server exit, and are reused by subsequent tasks. Useful for multi-task taskflows that need shared state across tasks.