Set Up Gmail With an App Password
Use the gmail preset when a Python script needs to receive mail through IMAP or send mail through SMTP with a Gmail App Password.
The preset allows only /usr/bin/python3 to open raw TLS connections to imap.gmail.com:993 and smtp.gmail.com:465.
OpenShell enforces the exact hosts, ports, and binary, but it cannot inspect individual IMAP or SMTP commands inside the encrypted connections. This preset does not grant Gmail REST API, Google OAuth, or service-account endpoints.
Google recommends App Passwords only for clients that cannot use Sign in with Google. This workflow stores the App Password inside the sandbox, where the agent can read it while the file exists. Create an App Password only for this workflow. Delete the uploaded file after the task. Revoke the App Password after the task.
Prerequisites
Prepare the Google Account before applying the preset:
- Turn on 2-Step Verification for the Google Account.
- Create an App Password for the sandbox workflow.
- Confirm that the account or Google Workspace administrator permits IMAP and App Passwords.
Google documents the TLS endpoints and ports in IMAP, POP, and SMTP.
Apply the Preset
Run these commands from the host:
Upload the App Password
Create gmail_config.json on the host outside any source checkout:
Restrict the host file. Prepare a sandbox directory. Upload the file. Restrict the uploaded copy:
Do not commit gmail_config.json or paste its contents into chat, logs, issues, or pull requests.
Download Recent Attachments
Save this standard-library example as download_attachments.py on the host.
It reads the 10 most recent messages without marking them as read and writes attachments under /sandbox/hand/gmail_attachments:
Upload the script. Run the script. Copy the attachment directory back to the host:
Treat every downloaded attachment as untrusted content. Do not execute an attachment in the sandbox or on the host without reviewing it.
Send a Test Message
Save this standard-library example as send_email.py on the host.
The example sends a test message back to the configured account:
Run these commands:
Remove Credentials and Access
Delete the host and uploaded credential files, along with the temporary sandbox files, after downloading any attachments you need:
Removing the preset does not delete uploaded files or revoke the App Password. Revoke the dedicated App Password in your Google Account when the sandbox no longer needs it.
Related Topics
- Common Integration Policy Examples lists other maintained integration presets.
- Apply Policy Presets explains preset persistence and reapplication.
- Credential Storage explains NemoClaw credential boundaries.