Enterprise code bastion: Claude works on the code with no file or shell access
Native file and shell tools are exactly the leak vector security won't sign off on. An enterprise code bastion removes them entirely (--tools "") and routes every action through a filtering MCP mediator that runs commands in an isolated container: Claude reasons and decides, but never touches code, secrets, or infrastructure directly.
Problem
A large organization cannot hand an AI tool uncontrolled access to source code, secrets, and infrastructure. But it still wants Claude to understand the codebase and do real work in it. The naive setup gives the agent native file and shell tools — and that is exactly the access security cannot sign off on: nothing stops the agent from reading a secret, writing outside the task, or running a destructive command on the host.
Methodology
Don't constrain the agent with a prompt — constrain it with architecture. Strip the native tools entirely and route every interaction through a mediator that executes commands in a sandbox.
-
1. Project + task is the unit of work. A
projects/directory and atasks/directory. Each pair spins up a dedicated Docker container with only that project mounted at/workspace. Sessions don't see each other. -
2. Claude with no tools. Claude Code launches with
--tools ""— native read, write, and command execution are off. On its own the agent cannot read, change, or run anything in the system. -
3. Access only through MCP. Instead of native
tools, Claude talks to an MCP server over HTTP (FastMCP, stateless, port
17847). The session resolves fromIDP_SESSION_ID; the server looks it up insessions.csvand operates on its container. Exposed tools:ping,echo,secureBash. -
4. Isolated execution. The command runs via
docker execinside the session container, not on the host, with a timeout (IDP_EXEC_TIMEOUT, default300s). The result —stdout/stderr/exit_code— goes back to Claude. -
5. Full audit. Every MCP request is written to
logs/mcp.log(JSON Lines, body truncated at16 KB) — a trail for review and compliance.
Starting a session is a real
docker run from the
launcher, and what's absent from it matters:
# scripts/start_session.py — how the session container comes up
cmd = ["docker", "run", "-d", "--name", session_id, # session_id = idp-<uuid>
"-v", f"{project_path}:/workspace", "-w", "/workspace",
"-e", f"IDP_SESSION_ID={session_id}",
image, "sleep", "infinity"] # image = ubuntu:22.04 (demo)
The launcher also closes path traversal before
docker run — the project
name can't escape projects/:
if not project or project in (".", "..") or "/" in project or "\\" in project:
sys.exit(f"Invalid project name: {project!r}")
project_path = (PROJECTS_DIR / project).resolve()
if not str(project_path).startswith(str(projects_root) + os.sep):
sys.exit(f"Invalid project path: {project!r}")
Launching Claude — note the
--tools "":
./scripts/start_session.py demo demo-001 # → idp-<uuid>, container, row in sessions.csv
eval "$(./scripts/claude_command.py demo demo-001)"
# the generated command:
IDP_SESSION_ID=idp-aae519cd... \
claude --append-system-prompt "<guard rules>" \
-p "<task text from tasks/demo-001.md>" \
--tools "" # native tools off; only MCP left (secureBash, ...)
Artifact
github.com/dobryakov/enterprise-code-bastion
(Python, Docker, MCP-over-HTTP). A working skeleton of the bastion: a session launcher
with a path guard, a command builder, a FastMCP server with
secureBash and
docker exec, audit
middleware, a CSV session registry. It's an inspectable artifact — which is exactly why
it's worth naming honestly what's in it and what isn't yet (see below).
Where it breaks
The honest breakdown matters more than the method here: for a CISO audience, overstating a control that doesn't exist is worse than not having it.
-
There is no command gate in the artifact — this is the
big one.
secureBashruns arbitrary bash: the path is short and unfiltered —secureBash → run_bash_in_container → docker exec session_id bash -lc command. There is no allowlist and no LLM check in the code. The filtering layer is the intended next component, not a shipped one. How I'd approach it: the build order is deliberate — isolation and perimeter first (the container,--tools "", the single path through MCP, the audit trail), then the gate, because a filter without isolation is useless while isolation without a filter already narrows the blast radius to the container. A production gate is two layers: a deterministic allowlist (what's permitted at all) as the hard boundary, and an LLM classifier (is it appropriate within the task) as a soft layer on top. An LLM as the sole arbiter is unacceptable — it carries its own prompt-injection surface. -
The demo container isn't hardened.
ubuntu:22.04,docker runwith no--user,--cap-drop,--read-only,--network, or memory/CPU limits — meaning root inside and full network egress. The isolation protects the host, but a compromised container on its own is still a blast radius. Production mitigation:--user 1000,--cap-drop=ALL,--read-only+ tmpfs,--networkwith an egress allowlist (or the agent exfiltrates the code), and--memory/--cpus. What to monitor: container network egress and outbound connection attempts. -
The MCP endpoint has no authentication. The session
resolves from the
IDP_SESSION_IDquery parameter — whoever knows or guesses the id runs commands in someone else's container. In the demo the server listens on127.0.0.1, but in production, "externalized beyond the perimeter" with no auth, that's a hole. Mitigation: mTLS or a signed session token on the MCP, id rotation, binding the session to its caller. What to monitor: calls tosecureBashwith a foreign/expiredIDP_SESSION_IDinlogs/mcp.log. -
A flat registry doesn't carry governance.
sessions.csvis a fine append-only journal, but without concurrency control, RBAC, or "who approved what." At organization scale you need a real session store and an approval workflow. The audit log also truncates the body at 16 KB — long output won't land in the trail in full.
For whom and why
This is the security model for AI-on-code where security has to sign off: isolation, least privilege, a single narrow path, full audit. Not a tutorial on running an agent — the architecture conversation about the line between giving the agent enough to be useful and keeping it physically unable to act outside what's permitted. The artifact shows the skeleton honestly: Claude reasons and decides, but with no tools and no direct access — and the open gaps (the gate, container hardening, auth) are named exactly where a security engineer will look for them.
Keep reading
About the author
Grigoriy Dobryakov — fractional / interim eng + AI leadership
Letting AI agents touch your codebase — safely?
Isolation, least privilege, per-operation filtering, and an audit trail for AI-on-code — with a working artifact, not a policy deck.
Discuss a fractional audit Email meOther breakdowns
An engineering breakdown series: real task → methodology → working artifact → honest breakdown of where it fails.
Back to series →