Skip to content

feat: run compilation inside sandbox containers - #213

Merged
Shubh942 merged 3 commits into
c2siorg:mainfrom
Uday9909:feat/docker-sandbox-compile
Aug 24, 2026
Merged

feat: run compilation inside sandbox containers#213
Shubh942 merged 3 commits into
c2siorg:mainfrom
Uday9909:feat/docker-sandbox-compile

Conversation

@Uday9909

Copy link
Copy Markdown
Contributor

Summary

PR 3/3 of the Docker sandbox phase (branch contains #212's commits; PRs #211 + #212 should merge first). When GDBUI_DOCKER=true, compilation now runs inside the per-session sandbox container via docker exec, so compile + debug are both isolated — closing the gap where g++ still ran on the host.

Changes

  • gdbui_server/sandbox.pystart_container is now idempotent: a Docker name-conflict (container already running for the session) returns the existing name instead of None. Required because compile runs before start_gdb, and a second docker run --name would collide and fail closed.
  • gdbui_server/main.pycompile_code() builds the compiler command by mode: sandbox on → docker exec -i <name> g++ -g -O0 /workspace/<src> -o /workspace/<bin>; sandbox off → unchanged host g++. Fails closed: if the container can't start while sandboxing is on, compilation is refused (400 COMPILATION_FAILED) and subprocess.run is never reached.
  • gdbui_server/tests/test_sandbox.py — +2 tests (idempotent start on name-conflict; None on other CalledProcessError).
  • gdbui_server/flask_test.py — +2 tests (docker-exec compile args; fail-closed when container start fails).
  • README.md — new Sandbox Mode (Docker) section; the call system("rm -rf /") limitation now points to it as the mitigation.

Behavior

  • Disabled (default, GDBUI_DOCKER=false): zero behavioral change. All existing tests pass unchanged.
  • Enabled: g++ executes in the container (--read-only rootfs, --network none, --tmpfs /tmp). The output/{session_id}/ bind mount at /workspace means the compiled .exe lands exactly where GDB (start_gdb) already looks.

Test Plan

  • python3 -m unittest discover -s tests56 passing (54 existing + 2 new)
  • python3 flask_test.py18 passing (16 existing + 2 new)
  • Manual (optional, needs Docker + image built): GDBUI_DOCKER=true → compile + debug a program, confirm g++ ran in the container

Notes

Stacked on #211 (infra) and #212 (lifecycle wiring) — review/merge those first.

Uday9909 added 3 commits July 29, 2026 13:33
When GDBUI_DOCKER=true, start_gdb runs GDB inside a per-session
container via docker exec instead of on the host. Binary path
switches to /workspace/<name>.exe (bind-mounted output dir).

Container teardown mirrors controller teardown across all paths:
stop_gdb, end_session, expiry cleanup, and program-switch in
start_gdb. Fails closed if the container cannot start.
When GDBUI_DOCKER is enabled, g++ now runs inside the per-session
sandbox container via docker exec instead of on the host, so compile
and debug are both isolated. start_container is idempotent (a second
call reuses the running container instead of failing on the name
conflict), and compilation fails closed if the container can't start.
README gains a Sandbox Mode section.
@Shubh942
Shubh942 merged commit a96657b into c2siorg:main Aug 24, 2026
2 checks passed
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