How to Configure Codex SSH Sandbox
You set up a codex ssh sandbox by running the agent in an isolated host with limited keys. You then lock down the remote target account so the agent only runs safe commands. Many teams start by giving AI coding agents their own local keys and broad server logins. When roles are too broad, a bad prompt or agent mistake can delete files or leak secrets. A tight setup stops the agent from wandering outside its assigned work folder. How a codex ssh sandbox works An AI coding agent often needs a s
SSH Access Management + AI Sandbox Environments: the complete guide
Architecture patterns, implementation strategies, and security best practices. Delivered to your inbox.
You set up a codex ssh sandbox by running the agent in an isolated host with limited keys. You then lock down the remote target account so the agent only runs safe commands. Many teams start by giving AI coding agents their own local keys and broad server logins. When roles are too broad, a bad prompt or agent mistake can delete files or leak secrets. A tight setup stops the agent from wandering outside its assigned work folder.
How a codex ssh sandbox works
An AI coding agent often needs a shell to test code, inspect logs, or check system state. In a basic setup, the agent runs on a user laptop or a build server. If it uses the developer's own SSH key, it gets every permission that developer holds. A proper sandbox splits the agent from the human user right at the start.
First, you place the agent inside an isolated container or virtual machine. This local box only holds the code repo and a dedicated SSH key for the agent. Next, you prepare the remote target host where the agent will run commands. You create a dedicated Linux user on that host with read-only rights to specific folders. You never add this user to admin groups or give it root rights.
Instead of raw static keys, teams can use OpenSSH certificates to manage logins. A certificate authority key signs the agent's public key and attaches an identity name. It also sets a list of allowed user or host names called principals. OpenSSH added this simpler certificate format in version 5.4 to avoid complex TLS setups. You can set a short time limit when signing so the key expires after the task.
What native SSH limits solve and what they miss
Native SSH rules and OS permissions solve the basic login problem. They verify who logs in and which Linux user account owns the session. Certificate options can also force a single command or turn off port forwarding. If someone steals a signed certificate after it expires, the target host rejects the login.
Still, host login checks leave a large operational gap during active work. Once the session starts, SSH does not inspect the stream of commands in flight. An agent with shell rights can still read sensitive files inside its allowed folder. If log files or config files hold customer emails, phone numbers, or card numbers, the agent reads them. Those raw values then flow back into the model context window.
SSH Access Management + AI Sandbox Environments: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Static OS rules also lack a step-by-step approval flow for risky actions. You either give the Linux account write access to a path or you block it. You cannot pause a single shell command to ask a human reviewer for approval. Teams also struggle to tie every shell command back to a specific agent task. Standard system logs only show the Linux username, not the full command output or prompt history.
Best practices for safe agent shell access
Start by treating every AI coding agent as an untrusted contractor. Never share personal SSH agent sockets with a local container or remote task runner. When you forward a personal socket, any process in that box can use your keys.
Keep the remote target user as small as possible. Mount code and log folders as read-only whenever the agent only needs to debug an issue. If the agent must restart a service, restrict its permissions to that single service command. Rotate keys often and keep validity windows short so old credentials never linger on disk. Finally, scrub or mask sensitive fields like national IDs and emails before the agent reads the output.
Check SSH commands and file transfers on the host
OpenSSH keys and certificates decide who can log into a Linux host. They do not check what a one-shot command or file transfer does once the session starts. With hoop.dev, you run an open-source SSH server with guardrails inline on the host. On every one-shot command or file transfer an AI agent or engineer runs against production, hoop.dev decides to pass, mask, block, or hold it for human review.
When a caller runs a one-shot command or moves a file, hoop.dev guardrails check the command or path before it runs, and hoop.dev data masking masks matched sensitive patterns in downloads and output. Interactive shells carry no guardrails because keystrokes have no statement boundary. Teams can turn interactive shells off and allow only commands and file tasks. The audit trail logs who connected and what was allowed or refused, without storing keystrokes or file bytes. See the source on GitHub.
Frequently asked questions
Why should I avoid SSH agent forwarding with AI coding tools?
Agent forwarding lets any process inside the sandbox use your local keys to reach other servers. A confused or tricked agent could log into production hosts that were not part of its task.
How do OpenSSH certificates improve on standard public keys?
A certificate authority signs the key with an identity name, allowed principals, and an expiration time. You do not need to copy and delete public keys across dozens of target servers.
Can native SSH stop an agent from reading sensitive data in logs?
No, native SSH only manages the encrypted tunnel and the initial user login check. If the remote Linux user can read a log file, SSH sends the full text back to the agent.
Related guides
In this post