Security
Agent Cloud executes real shell commands on your machine and interacts with cloud provider APIs. This page covers the security measures in place and best practices for safe usage.
Shell Command Sanitization
Section titled “Shell Command Sanitization”Agent Cloud executes cloud CLI commands using Node.js child_process.exec. All user-provided values that end up in shell commands pass through sanitization functions defined in src/utils/shell.ts.
Resource Name Sanitization
Section titled “Resource Name Sanitization”Cloud resource names (cluster names, service names, bucket names) are sanitized with sanitizeResourceName():
function sanitizeResourceName(name: string): string { return name .toLowerCase() .replace(/[^a-z0-9-]/g, '-') // Only allow lowercase alphanumeric and hyphens .replace(/--+/g, '-') // Collapse multiple hyphens .replace(/^-|-$/g, '') // Remove leading/trailing hyphens .substring(0, 63); // Enforce max length}This prevents injection through resource names. For example, if a package.json has "name": "my-app; rm -rf /", the sanitized name becomes my-app--rm--rf--.
Shell Escaping
Section titled “Shell Escaping”The shellEscape() function wraps values in single quotes with proper escaping:
function shellEscape(str: string): string { str = str.replace(/\0/g, ''); // Remove null bytes return "'" + str.replace(/'/g, "'\\''") + "'"; // Single-quote wrapping}Path Sanitization
Section titled “Path Sanitization”The sanitizePath() function prevents directory traversal attacks:
function sanitizePath(filePath: string, basePath?: string): string { const cleaned = filePath.replace(/\0/g, ''); const resolved = path.resolve(base, cleaned); if (!resolved.startsWith(path.resolve(base))) { throw new Error('Path traversal detected'); } return resolved;}This ensures file operations stay within the project directory. A path like ../../etc/passwd would be rejected.
Credential Handling
Section titled “Credential Handling”API Keys
Section titled “API Keys”- AI API keys are stored in
.envfiles and loaded viadotenv - Keys are never logged, displayed, or included in deployment commands
- The
initcommand uses masked input (inquirerpassword type) when collecting keys .envfiles should be added to.gitignoreto prevent accidental commits
Cloud Credentials
Section titled “Cloud Credentials”Agent Cloud does not store cloud credentials. It relies on the native CLI tools:
- AWS: credentials from
~/.aws/credentialsor environment variables (AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY) - GCP: credentials from
gcloud auth loginstored in~/.config/gcloud/ - Azure: credentials from
az loginstored in~/.azure/
Agent Cloud only reads these indirectly by invoking the CLI tools. It does not parse credential files directly.
Environment Variables in Deployments
Section titled “Environment Variables in Deployments”When deploying, Agent Cloud reads .env from the project directory and forwards environment variables to the deployed application (e.g., as ECS task definition environment, Cloud Run env vars, or Azure App Settings). Be aware that:
- Only variables from the project’s
.envfile are forwarded - System-level environment variables are not automatically included
- Sensitive values are passed to cloud APIs over HTTPS
Workflow State Persistence
Section titled “Workflow State Persistence”The Mastra workflow engine persists state to a local LibSQL database (agent-cloud.db). This file contains:
- Workflow run metadata
- Suspend payloads (deployment plans, including service names and commands)
- Resume data (approval status)
This file is stored locally and is not transmitted anywhere. Add it to .gitignore:
agent-cloud.dbAI Model Interactions
Section titled “AI Model Interactions”When using AI-powered features (analyze --ai or deploy), project information is sent to the configured AI model provider:
- Google Gemini: project analysis data is sent to Google’s API
- OpenAI: project analysis data is sent to OpenAI’s API
This includes:
- Directory structure and file names
- Contents of configuration files (package.json, requirements.txt, etc.)
- Dependency lists
Source code files are generally not sent unless the AI agent specifically uses fileReaderTool to read them. The agent’s instructions focus it on configuration files rather than source code.
Reducing Data Exposure
Section titled “Reducing Data Exposure”- Use
cloud-agent analyze(without--ai) for local-only analysis that sends nothing to external services - Review the AI provider’s data retention policies
- For sensitive projects, consider using
--localanalysis and manually configuring deployment
File System Access
Section titled “File System Access”The analyzer agent’s tools can read files within the project directory. The fileSystemTool skips common directories (node_modules, .git, dist, build, coverage) to avoid reading unnecessary files. The fileReaderTool reads specific files the agent requests.
Path validation ensures tools cannot read files outside the project directory.
Best Practices
Section titled “Best Practices”- Always review deployment plans before approving. The
deploycommand shows you every command that will be executed. - Add
.env,.agent-cloud/, andagent-cloud.dbto.gitignore. - Use least-privilege IAM roles for cloud deployments. Only grant the permissions needed for your deployment type.
- Run
cloud-agent statusbefore deploying to verify your environment is correctly configured. - Keep cloud CLIs updated to get the latest security patches.
- Audit deployment history with
cloud-agent historyto track what was deployed and when.