Secure development with AI in VS Code
Agents can change files, run programs, and act on external services using the access available to their session. Before starting a task, choose the capabilities and access it needs. During the task, review consequential actions. Before integrating the result, check the actual changes and validation.
This guide provides a practical baseline and steps for responding to unexpected behavior. Controls differ by agent harness and execution environment. Don't assume that a setting for one harness protects another, or that completing a checklist eliminates the risk of mistakes or prompt injection.
Recommended security baseline
-
Review a project before trusting it. Open unfamiliar projects in Restricted Mode. Check executable configuration, including tasks, hooks, and MCP server commands, before granting Workspace Trust. Workspace MCP configurations can start without a separate trust prompt after you trust the project.
-
Confirm the session's workspace and execution environment. Check the folder or worktree, harness, and whether commands run on your machine, a remote host, or in the cloud. Access and credentials apply where the tools run.
-
Choose an appropriate permission level. In Copilot sessions, Manual permissions lets you review actions that aren't already approved. Prefer one-time approval when unsure. Save an approval only when you intend to permit matching future calls. See permission levels and approval scopes.
-
Restrict command access and verify it. Where supported, turn on sandboxing and configure file and network access. Outbound network access is allowed by default in the Copilot sandbox. Run
/sandbox policyin a Copilot session to check the effective restrictions. -
Limit tools and credentials to the task. Review tool sources before installing or connecting them. Use credentials with only the required service permissions, and don't place secrets in prompts or shared configuration.
-
Review changes before integrating them. Inspect the resulting files and tests before committing, merging, or creating a pull request. Include changes made through terminal commands and external tools, not just those listed by an edit tool. See review agent changes.
Limit access for the task
Choose a control based on what you want to limit:
| Your goal | Control to use | Important limit |
|---|---|---|
| Review actions before they run. | Permission levels and tool approvals. | Manual permissions doesn't prompt for every action. Runtime decisions, rules, and saved approvals can permit calls automatically. |
| Stop offering an optional capability. | Tool availability or the MCP server controls. | Not every built-in tool can be deselected. A tool selection is different from approving its actions. |
| Restrict command access to files or networks. | Agent sandboxing. | It covers supported processes, not every tool. Developer-tool directories and credentials can add access beyond the workspace. |
| Ask before supported edits to sensitive files. | Sensitive-edit approval. | It isn't a file-read restriction or a guarantee against changes from commands and other tools. Auto-approval modes can bypass these checks. |
| Keep concurrent code changes separate. | Separate worktrees. | A worktree separates working files, not access to the machine or external services. |
If a sandboxed command is blocked, review the path or destination it needs. Prefer narrow additional access over running the command outside the sandbox. Approval to run a command doesn't expand its sandbox access.
Review executable customizations
Extensions, plugins, MCP servers, skills, and hooks can include code that runs in your environment. Review the publisher, source, requested access, and configured commands before using them. Trusting a publisher or connecting a server doesn't establish that every tool result is safe.
Workspace .vscode/mcp.json and .mcp.json configurations inherit Workspace Trust. Review them before trusting the repository, including changes made by others. For servers from other sources, review any separate MCP trust prompt.
A hook can inspect an action or record events, but its coverage and failure behavior matter. Don't treat a custom hook as a universal permission check or a complete audit trail. Use the supported hook contract and test the behavior you depend on. Instructions guide the model; they aren't an enforcement boundary.
Protect credentials and external services
Before sharing project information, check your organization's requirements for the model provider and connected services. Working on local files doesn't mean model processing stays on your computer. See where information goes for the distinction between model requests, tool calls, and stored history.
Use the authentication method supported by each integration. For MCP servers, follow the authentication and secrets guidance. Don't commit tokens or populated authentication headers, and don't assume a personal configuration file is a secret store.
Before approving an external action, check both the destination and what the action will do. Access to an allowed service can permit writes, deployments, or other changes, not just reading data. Review which credentials a sandboxed process can use, including Git and GitHub CLI credentials and developer-tool configuration.
For Copilot's built-in web fetch, URL approval permits contacting the destination. It doesn't provide a separate prompt to review the response before the model uses it. Treat returned content as data, not authorization for unrelated actions. The deprecated Local harness has separate request and response controls.
Supported shell-authentication prompts in Copilot sessions use masked input for passwords and passphrases (Experimental). The answer goes to the requesting program, not to the model or chat history. This protection applies only to the dedicated authentication prompt. Review the requesting command and destination, and don't paste secrets into ordinary chat or command text.
For computer use Computer use is experimental and might change or be removed. , review application-access requests and avoid exposing sensitive information in other windows. Desktop tools can act outside your workspace. See the provider's limitations and risks.
Approvals and review
Review the actual tool inputs, not only the agent's explanation. Check commands, paths, URLs, accounts, and proposed changes against the task you requested. If an action is wrong, decline it and tell the agent what to change.
Keep saved approvals narrow. In this Session can remain effective when you resume that session; closing the window doesn't withdraw it. Use approval management to inspect supported saved decisions, and check the documented limits for remote approvals.
In Copilot sessions, Autopilot controls continued work, not the permission level. Assisted permissions uses model-based review that can make mistakes. Allow all and global auto-approval skip ordinary confirmation prompts. Choose these controls deliberately rather than treating fewer prompts as evidence that actions are safe. See approval behavior by harness.
Approving an edit and accepting its result are separate decisions. Edits can already be saved when you review them. Before integrating:
- Inspect changed and untracked files. The working set doesn't track every change made through commands, scripts, or external tools.
- Check the actual test and validation output. An agent's statement that the task is complete isn't proof that it meets the requirements.
- Review effects outside the repository, such as a deployment, created resource, or changed service configuration.
Use the review workflow for file changes. Use the affected service's controls to inspect or undo external actions.
Remote and unattended work
Remote execution changes where actions happen. It doesn't remove the need to review access, credentials, and results.
Remote connections and GitHub environments
GitHub environments GitHub environments is in preview and might change before it becomes generally available. let supported clients connect to sessions on a development machine. Those clients receive trusted-owner access to sessions, tools, and workspace resources, not just one conversation. Only connect from clients and devices you trust, and protect the account used to register the host.
Session actions are mirrored to GitHub for catalog and history storage, and conversation content is not end-to-end encrypted. Review the sharing disclosure and your organization's data-handling requirements before registering a host.
For SSH or dev tunnels, protect the credentials and require tunnel authentication. Don't expose an agent host through anonymous access.
Disconnecting a client doesn't stop host tasks. To stop sharing, select Remote Connections > Off on the host. To halt active work, stop the task in its session. Neither action undoes completed effects. See disconnect or stop sharing.
Cloud sessions
Cloud sessions Cloud sessions is experimental and might change or be removed. run tools in a managed environment. Check the repository, session permissions, credentials, and data-handling requirements before sending code or task context. Local editor state, extension tools, and uncommitted changes aren't automatically transferred.
Don't assume local sandbox or approval settings configure the cloud service. Review the cloud session's actual controls, changes, and test results. Cloud execution separates work from your local machine, but can still affect services the session can access.
Closing the client or marking a task done isn't a cloud-resource shutdown action. Deleting a task also shouldn't be treated as confirmation that its compute was deleted. Follow cloud session lifecycle guidance.
Unattended cloud automations
Before enabling a cloud automation Cloud automations is in preview and might change before it becomes generally available. , test its prompt with a manual run. Restrict its allowed tools and event filters, and use Require write access to trigger where appropriate. Local approval and sandbox settings don't configure the cloud service.
Keep secrets out of automation prompts. An Only me definition can be private while its run sessions and logs remain visible to people with repository access. Check cloud automation security and usage.
Closing the application doesn't disable triggers. Disable the automation to prevent future runs, and use Stop separately to request cancellation of an active run. Neither action reverses completed changes.
Respond to unexpected behavior
If the agent attempts unrelated work, uses an unexpected destination, or makes changes you didn't intend:
- Stop the active request. Check whether background commands, other sessions, or scheduled automations are still running. Closing a chat or disconnecting from a host isn't a substitute for stopping work.
- Inspect what happened. Review tool inputs and outputs, changed and untracked files, and any actions on external services. Distinguish a proposed action from one that already completed.
- Review access before continuing. Check saved approvals, enabled tools, connected accounts, and sandbox exceptions. If an action was driven by untrusted content, don't approve follow-up requests solely because that content asks for them.
- Recover at the appropriate scope. Use file and checkpoint recovery for supported workspace changes. Use the external service's recovery controls for deployments or other remote effects.
- Follow your incident process if information might have been exposed. Contact your organization's security team when required, and revoke or rotate exposed credentials through the affected service. Resetting approval preferences doesn't revoke credentials.
Stopping a request doesn't undo completed commands or network requests. Inspect the result before restarting the task.
Enterprise policies
Your organization can restrict available harnesses, permission levels, tools, and network access. If a control is locked or required access is denied, contact the administrator rather than trying another harness to avoid the restriction.
Policy behavior differs by harness. For example, a policy that marks a tool ineligible for automatic approval doesn't necessarily require a person to confirm each call in a Copilot session. Check harness-specific policy behavior.
Claude and Codex can't enforce Copilot's enterprise-managed controls. They are disabled when those controls apply unless an administrator permits them. An exception doesn't make them enforce the same restrictions. See Claude and Codex availability.
Administrators should follow Manage AI settings in enterprise environments for configuration, deployment, and verification.