AI-assisted coding with tools like Claude Code can be enormously powerful - but with that power comes risks. AI development tools don't always follow instructions exactly, sometimes due to poorly thought-out prompts, user error, or even AI bugs and implementation issues.
The best practice for secure AI development is to run AI coding assistants like Claude Code in a containerized development environment. This provides elevated isolation from your host system, ensuring that any mistakes or unexpected behavior during AI-assisted coding has less of a chance to impact your local files or development environments. Along with other protections, you can feel more comfortable leveraging this power.
This PyCharm DevContainer template is specifically designed for secure Python development with JetBrains PyCharm Professional, Docker dev containers, and Claude Code as your AI coding assistant. This approach can be adapted to other IDEs (VS Code pioneered dev containers and has excellent support), other AI assistants, and alternative container solutions (Podman, Colima, Orbstack, etc.), as well as other programming languages.
This project has a companion blog article you can find here: Containerized Development: My Security Layer for AI Coding Tools
Important: Containerizing your Python development environment protects your host system, but doesn't protect your code, data, or remote systems. This template implements additional security best practices:
- β
Read-only SSH keys for git repositories - Project-specific deploy keys prevent accidental force pushes
- See .devcontainer/docs/GITHUB_SETUP.md for setup
- β
Project-specific AWS credentials - Isolated IAM users with minimal permissions prevent production access
- See .devcontainer/docs/AWS_SETUP.md for setup
- Automated setup script:
./scripts/setup-aws-iam-user.sh
- β
No host credential mounts - Your personal ~/.aws and ~/.ssh are never exposed to the container
- See .devcontainer/docs/MACOS_SECURITY.md for Docker file sharing
All security features are optional - the template works perfectly for vanilla Python development without AWS or GitHub SSH. Each feature gracefully degrades when not configured, with helpful status messages and setup guides.
This secure development environment template combines PyCharm Professional with DevContainers and integrated Claude Code for safe, reproducible AI-assisted Python development that works identically across all team members' machines.
- π Python 3.12 containerized development environment with complete dependency isolation
- π§ Claude Code AI assistant integrated and ready for secure AI-assisted coding
- π‘οΈ Complete host system protection - no local Python/dependencies conflicts
- π Reproducible team development - identical environment across all machines
- π¦ Persistent development storage - configuration and cache preserved between sessions
- β‘ JetBrains PyCharm Professional full IDE integration with secure container backend
- π Secure AI coding practices - isolated environment for safe AI development
- π Zsh with Oh My Zsh - syntax highlighting, autosuggestions, and git-aware prompt
- βοΈ Optional AWS integration - project-specific IAM users with automated setup
- π Optional GitHub SSH - read-only deploy keys for secure git operations
- π Comprehensive documentation - detailed guides for all features and setup
- PyCharm Professional (Community Edition lacks DevContainer support for this template)
- Docker Desktop (running and allocated 8GB+ RAM for containerized development)
- Anthropic Account (for Claude Code AI assistant - free tier available)
- macOS/Windows/Linux with Docker support
- 8GB+ RAM for Docker allocation
- 10GB+ free disk space for container images
git clone https://github.com/your-username/pycharm-claude-devcontainer.git
cd pycharm-claude-devcontainer- Launch PyCharm Professional
- File β Open β Select the project directory
- PyCharm will automatically detect the
.devcontainer/devcontainer.jsonconfiguration - Click "Reopen in Container" when prompted for secure containerized development
- PyCharm builds the container automatically
- Monitor progress in Services tool window
- Container downloads Python 3.12, installs tools, and configures environment
- Open PyCharm terminal (automatically connected to secure container)
- Run:
claude - Choose "Use Subscription" (recommended for team development)
- Authenticate via browser with your Anthropic account for AI-assisted coding
- Right-click
src/main.pyβ Run - Configure Python interpreter when prompted:
- Add Interpreter β System Interpreter
- Path:
/usr/local/bin/python3 - Click OK
- Run Python code: Right-click β Run
- AI coding assistance: Type
claudein terminal for intelligent code suggestions - Automated testing:
python -m pytest tests/ - Code formatting:
black src/ tests/
βββ .devcontainer/ # DevContainer configuration
β βββ devcontainer.json # Container settings
β βββ Dockerfile # Python 3.12 + Zsh + AWS CLI
β βββ setup.sh # Post-creation setup
β βββ start.sh # Smart AWS/GitHub detection
β βββ docs/ # Comprehensive setup guides
β β βββ AWS_SETUP.md # AWS credential management
β β βββ GITHUB_SETUP.md # GitHub SSH configuration
β β βββ MACOS_SECURITY.md # Docker file sharing security
β β βββ PYCHARM_TERMINAL.md # Zsh terminal setup
β βββ ssh/ # Project-specific SSH keys (optional)
β βββ README.md # SSH key instructions
βββ scripts/ # Utility scripts
β βββ setup-aws-iam-user.sh # Automated AWS IAM user creation
β βββ cleanup-aws-iam-user.sh # AWS IAM user cleanup
β βββ aws-permissions-config.example.sh # Policy template
β βββ README.md # Scripts documentation
βββ src/ # Python source code
β βββ __init__.py
β βββ main.py # Sample application
βββ tests/ # Test files
β βββ __init__.py
β βββ test_main.py # Sample tests
βββ .env.example # Environment variables template
βββ requirements.txt # Python dependencies
βββ CLAUDE.md # AI assistant context
βββ README.md # This file
- Open PyCharm β Project auto-connects to container
- Develop normally with full PyCharm features
- Use Claude Code for AI assistance:
claude - Run/debug/test as usual - all happens in container
# Application
python src/main.py # Run main application
# Testing
python -m pytest tests/ # Run all tests
python -m pytest tests/ -v # Verbose output
python-test # Alias for pytest (with zsh)
# Code Quality
black src/ tests/ # Format code
flake8 src/ tests/ # Lint code
mypy src/ # Type checking
python-format # Alias for black (with zsh)
python-lint # Alias for flake8 (with zsh)
# AWS (if configured)
aws-whoami # Show AWS identity
aws-account # Show AWS account ID
# Claude Code
claude # Start AI assistant
claude --help # Get help
# Shell Features (Zsh + Oh My Zsh)
# - Syntax highlighting (commands turn green/red as you type)
# - Auto-suggestions (gray text from history - press β to accept)
# - Git-aware prompt (shows branch and status)- Rebuild: Services β Docker β Container β Rebuild
- Restart: Services β Docker β Container β Restart
- Logs: Services β Docker β Container β View Logs
The container preserves between restarts:
- Claude Code configuration (
/home/developer/.claude) - Zsh command history (
/commandhistory/.zsh_history) - Python package cache (
/home/developer/.cache/pip)
Configure these features based on your project needs:
- AWS Integration - See .devcontainer/docs/AWS_SETUP.md
- Automated setup:
./scripts/setup-aws-iam-user.sh
- Automated setup:
- GitHub SSH Keys - See .devcontainer/docs/GITHUB_SETUP.md
- PyCharm Terminal (Zsh) - See .devcontainer/docs/PYCHARM_TERMINAL.md
- 8000: Development server
- 5000: Flask/API server
- 3000: Frontend server
- 8080: Alternative web server
PYTHONPATH=/workspace/src- Clean imports from src/DEVCONTAINER=true- Container environment indicator
# Temporary (lost on rebuild)
pip install package-name
# Permanent (add to requirements.txt)
echo "package-name>=1.0.0" >> requirements.txt
# Then rebuild containerEdit .devcontainer/Dockerfile to add tools:
RUN apt-get update && apt-get install -y \
your-new-tool \
&& rm -rf /var/lib/apt/lists/*- setup.sh: Runs once when container is first created
- start.sh: Runs every time container starts
- Customize these for project-specific setup
- Check Docker: Ensure Docker Desktop is running
- Memory: Increase Docker memory to 8GB+
- Clean build: Services β Container β Rebuild with --no-cache
- Restart PyCharm completely
- Check Services panel: View β Tool Windows β Services
- Recreate container: Remove and rebuild
- Reset config:
rm -rf /home/developer/.claude/* - Restart Claude: Run
claudeand reconfigure - Check authentication: Ensure Anthropic account is valid
- Path: Use
/usr/local/bin/python3 - Recreate: Add Interpreter β System Interpreter
- Verify: Run
which python3in container terminal
This template implements multiple layers of security for safe AI-assisted development:
- No host system access - AI assistant can't accidentally modify your local files
- Separate user context - Runs as non-root
developeruser - Volume isolation - Only project directory is mounted
All credential features are optional and gracefully degrade when not configured:
- Project-specific IAM users with minimal permissions
- Automated setup via
./scripts/setup-aws-iam-user.sh - No host ~/.aws mount - credentials generated from .env file
- Policy templates for common project types (data pipelines, web apps, ML)
- See .devcontainer/docs/AWS_SETUP.md
- Read-only deploy keys prevent accidental force pushes
- Project-specific keys in .devcontainer/ssh/
- No host ~/.ssh mount - personal SSH keys remain isolated
- See .devcontainer/docs/GITHUB_SETUP.md
- Restricted access - only project directory shared
- No ~/.aws or ~/.ssh exposure to containers
- See .devcontainer/docs/MACOS_SECURITY.md
- β Host system (container isolation)
- β Personal AWS credentials (not mounted)
- β Personal SSH keys (not mounted)
- β Production environments (project-specific IAM users)
- β Git history (read-only SSH keys)
- DevContainers Documentation
- PyCharm DevContainer Guide
- Claude Code Documentation
- Docker Best Practices
MIT License - feel free to use this template for any project.
Happy coding with AI assistance! π€