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
- β‘ Dual IDE support - PyCharm Professional or VS Code (your choice!)
- π 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
Choose Your IDE (you only need one):
- PyCharm Professional (Community Edition lacks DevContainer support)
- Paid (free for students/open source projects)
- Best for Python specialists
- Visual Studio Code (free)
- Free and open source
- Best for polyglot developers
- Requires "Dev Containers" extension
Required for Both:
- 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
If you want to create a new independent project from this template (not contribute to the template itself), choose one of these options:
This creates a completely independent project with no connection to the original template:
# 1. Clone the template to your new project name
git clone https://github.com/danjamk/pycharm-claude-devcontainer.git your-project-name
cd your-project-name
# 2. Remove the connection to the original repository
rm -rf .git
# 3. Initialize a fresh git repository
git init
git add .
git commit -m "Initial commit: Created from pycharm-claude-devcontainer template"
# 4. Create a new repository on GitHub (via web interface)
# Go to https://github.com/new and create your repository
# IMPORTANT: Do NOT initialize with README, .gitignore, or license (you already have these)
# 5. Connect to your new GitHub repository (replace YOUR-USERNAME and YOUR-REPO-NAME)
git remote add origin git@github.com:YOUR-USERNAME/YOUR-REPO-NAME.git
git branch -M main
git push -u origin mainIf the repository has enabled the template feature:
- Visit https://github.com/danjamk/pycharm-claude-devcontainer
- Click the green "Use this template" button (top right)
- Choose "Create a new repository"
- Name it (e.g.,
your-project-name) - Clone your new repo:
git clone git@github.com:YOUR-USERNAME/your-project-name.git
This creates a brand new repository with no git history and no connection to the original.
Simplest manual approach:
- Visit https://github.com/danjamk/pycharm-claude-devcontainer
- Click Code β Download ZIP
- Extract to a folder with your project name
- Initialize git:
cd your-project-name git init git add . git commit -m "Initial commit: Created from pycharm-claude-devcontainer template"
- Create repo on GitHub and connect as shown in Option 1, step 4-5
Update these files with your project-specific information:
- README.md - Replace with your project description
- CLAUDE.md - Update with your project context for AI assistance
- .env.example - Add any project-specific environment variables
- requirements.txt - Update with your project dependencies
Now proceed with the Quick Start guide below to set up your development environment.
Important: When you use this template for your project, contributors can choose whether to use the DevContainer or develop locally. The DevContainer provides consistency and convenience, but is not required.
When contributors join your project, they have two options:
- β Automatic environment setup with all dependencies
- β Guaranteed identical environment across all team members
- β No "works on my machine" issues
- β Requires Docker + PyCharm Professional or VS Code
Contributors can work normally without Docker:
# 1. Clone your repository
git clone git@github.com:your-username/your-project.git
cd your-project
# 2. Create a Python virtual environment
python3 -m venv venv
source venv/bin/activate # or `venv\Scripts\activate` on Windows
# 3. Install dependencies from requirements.txt
pip install -r requirements.txt
# 4. Set PYTHONPATH for clean imports (optional but recommended)
export PYTHONPATH="${PYTHONPATH}:$(pwd)/src" # Add to .bashrc/.zshrc
# 5. Develop normally
python src/main.py
python -m pytest tests/- Python 3.12+ (or compatible version specified in your project)
- pip for package management
- Dependencies from
requirements.txt - Environment variables from
.env.example(if applicable) - Their own preferred IDE/editor
When you customize this template for your project, add a section like this to your README:
## Development Setup
### Option A: DevContainer (Recommended)
Provides automatic setup with all dependencies and tools configured.
**Requirements**: Docker Desktop + PyCharm Professional (or VS Code)
1. Open project in PyCharm
2. Click "Reopen in Container" when prompted
3. Wait for container to build (first time only)
4. Start developing!
### Option B: Local Development
Standard Python development without Docker.
**Requirements**: Python 3.12+
1. Clone the repository
2. Create virtual environment: `python3 -m venv venv`
3. Activate: `source venv/bin/activate`
4. Install dependencies: `pip install -r requirements.txt`
5. Set PYTHONPATH: `export PYTHONPATH="${PYTHONPATH}:$(pwd)/src"`
6. Run tests to verify: `python -m pytest tests/`
Both approaches work perfectly - choose what fits your workflow!The DevContainer is a convenience tool that ensures consistency, not a requirement. Your project's Python code works with or without it - contributors choose what works best for them.
Choose your IDE: This template works with both PyCharm Professional and VS Code. Follow the guide for your preferred IDE.
# If you just created the project, you're already in the directory
# Otherwise, navigate to it:
cd your-project-name- 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/
- Open VS Code
- Click Extensions icon (sidebar) or press
Cmd+Shift+X(macOS) /Ctrl+Shift+X(Windows/Linux) - Search for "Dev Containers" by Microsoft
- Click Install
Or install from command line:
code --install-extension ms-vscode-remote.remote-containers# Navigate to your project
cd your-project-name
# Open in VS Code
code .When VS Code opens:
- A notification appears: "Folder contains a Dev Container configuration file"
- Click Reopen in Container
Or use Command Palette: Cmd+Shift+P / Ctrl+Shift+P β Dev Containers: Reopen in Container
- VS Code builds the container automatically
- Progress shown in bottom-right corner
- Click "show log" to see detailed build progress
- Python extensions are automatically installed
Once the container is ready:
- Open integrated terminal: Press
Ctrl+`(backtick) - Terminal is automatically connected to container with Zsh
- Run:
claude - Choose "Use Subscription" (recommended)
- Authenticate via browser with your Anthropic account
The Python interpreter is automatically configured:
- Check bottom-right status bar: should show
Python 3.12.x - If needed, click and select
/usr/local/bin/python3
- Run Python: Right-click file β Run Python β Run Python File in Terminal
- Run tests: Click testing flask icon (sidebar) or run
python -m pytest tests/ - Debug: Set breakpoints and press
F5 - Claude Code: Type
claudein terminal for AI assistance - Format: Right-click β Format Document (uses Black automatically)
For detailed VS Code setup, see .devcontainer/docs/VSCODE_SETUP.md
βββ .devcontainer/ # DevContainer configuration
β βββ devcontainer.json # Container settings (PyCharm + VS Code)
β βββ 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
β β βββ VSCODE_SETUP.md # VS Code complete setup guide
β βββ 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
- VS Code Setup - See .devcontainer/docs/VSCODE_SETUP.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 Specification - Official DevContainer standard
- PyCharm DevContainer Guide - JetBrains official docs
- VS Code DevContainers - Microsoft official docs
- VS Code Python Tutorial - Python in VS Code
- Claude Code Documentation - AI assistant docs
- Docker Best Practices - Container optimization
MIT License - feel free to use this template for any project.
Happy coding with AI assistance! π€