Keep your agent safe from untrusted tools and prevent credential leaks.
Run Claude Code or another agent in a minimal container to avoid security leaks that can happen when installing untrusted applications and sharing credentials in the same container as the agent.
- Avoid exposing your host system or credentials to the agent.
- Rely on safe tools provided by the coding agent.
- Add tailored agent skills.
What about untrusted third-party tools and credentials?
- Third-party tools and credentials are handled in separate containers and made available to the coding agent via a gateway approach.
Run this like you would any other CLI-based agent:
- in terminal, run
docker compose up --build - in terminal, connect to container via
docker compose exec agent /bin/bash - launch
claudein the default/workspacefolder and then login
Load up your agent with skills and plugins.
This project includes an example service that demonstrates the gateway pattern for safely integrating third-party tools.
The source of the OpenAI Image Generation Service is available at:
https://github.com/briangershon/openai-image-gen
The openai-image-gen service is defined in docker-compose.yml:
openai-image-gen:
image: ghcr.io/briangershon/openai-image-gen:latest
security_opt:
- no-new-privileges:true
tmpfs:
- /tmp
secrets:
- openai_api_key
volumes:
- ./workspace/generated-images:/app/images:rw
networks:
- agent-network
# Port NOT exposed to host - only internal accessKey features:
- Runs on internal
agent-network(not exposed to host) - API credentials managed via Docker secrets
- Generated images stored in shared workspace
- No privilege escalation allowed
- Create the secrets directory and add your OpenAI API key:
mkdir -p secrets
echo "your-openai-api-key-here" > secrets/openai_api_key.txt- Start the services:
docker compose up --buildFrom inside the agent container, call the service via the internal network:
# Connect to agent container
docker compose exec agent /bin/bash
# Generate an image
curl -X POST http://openai-image-gen:5000/generate \
-H "Content-Type: application/json" \
-d '{
"prompt": "A serene mountain landscape at sunset",
"model": "dall-e-3",
"size": "1024x1024",
"quality": "standard"
}' | jq .
# Images are saved to /workspace/generated-images/
ls /workspace/generated-images/The service returns JSON with image URLs and metadata. Generated images are accessible in the shared workspace/generated-images directory.
- Run the coding agent in an agent container with access only to the current working directory, with no access to the rest of the host system.
- Persist the coding agent's credentials inside the container so you stay logged in after the initial setup. Since projects may require different credentials, avoid switching LLM accounts when moving between projects.
- Do not run untrusted third-party applications in the agent container.
- Rely on Agent Skills to provide additional features and knowledge.
- Use a gateway container to expose tools running in other containers, keeping third-party tools and their credentials separate from the agent.