Empowering AI Agents with Secure Desktop Access: A Step-by-Step Guide to Amazon WorkSpaces for Agents
Overview
Enterprise workflows often rely on legacy desktop applications that lack modern APIs. According to a 2024 Gartner report, 75% of organizations run such applications, making it difficult for AI agents to automate processes. Amazon WorkSpaces now allows AI agents to securely operate these applications without requiring costly modernization. By leveraging the same managed virtual desktops used by employees, you can give agents governed access to desktop environments. This tutorial walks you through setting up a WorkSpaces environment for AI agents, from creating a stack to integrating with agent frameworks like LangChain or CrewAI.

Prerequisites
Before you begin, ensure you have the following:
- AWS Account with permissions to create WorkSpaces resources.
- IAM User or Role with policies for
workSpaces:CreateStack,workSpaces:CreateApplication,iam:PassRole, andec2:CreateVpcEndpoint. - WorkSpaces Directory already set up (or you can create one during the stack creation).
- Agent Framework (e.g., LangChain, CrewAI, or Strands Agents) prepared with MCP support.
- VPC with Subnets that can reach the WorkSpaces endpoints.
- Familiarity with the AWS Management Console or AWS CLI.
Step-by-Step Instructions
1. Create a WorkSpaces Applications Stack
Start by navigating to the Amazon WorkSpaces console. Under Applications, choose Create stack. This defines the environment for your agents.
- Name and Configuration – Enter a stack name (e.g.,
AI-Agents-Stack). - Fleet Association – Select an existing WorkSpaces fleet or create a new one. The fleet determines the compute resources for agent sessions.
- VPC Endpoints – Configure at least one interface VPC endpoint for WorkSpaces (required for agent connectivity).
- AI Agent Access – In Step 3 of the creation workflow, you'll see two options:
- No AI agent access (default for human users)
- Add AI Agents – Select this to enable agent access.
After choosing Add AI Agents, specify an IAM role that the agent will assume. This role must have permissions to call workSpaces:StartApplication and workSpaces:GetApplication. Review and create the stack.
2. Configure the Application for the Agent
Once the stack is ready, create an application within it. This application points to the desktop session the agent will use.
- In the WorkSpaces console, go to Applications and choose Create application.
- Select the stack you just created.
- Provide details:
- Application name (e.g.,
MainframeLegacyApp) - Desktop image – Choose a WorkSpaces bundle that includes the required legacy software.
- Agent permissions – Define which actions the agent can perform (e.g., click, type, read screen).
- Application name (e.g.,
- Ensure the application uses MCP (Model Context Protocol). This is enabled by default, but verify in the advanced settings.
3. Set Up IAM Permissions for the Agent
Create or update an IAM role for your agent. Attach the following policy:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"workSpaces:StartApplication",
"workSpaces:GetApplication",
"workSpaces:DescribeApplications"
],
"Resource": "*"
}
]
}
Additionally, grant the agent permission to assume this role from its identity provider.
4. Connect Your Agent Framework
Amazon WorkSpaces supports MCP, so any agent framework that implements it can connect. Below is an example using LangChain with the WorkSpacesTool (hypothetical wrapper):

from langchain.agents import initialize_agent, Tool
from langchain_community.agent_toolkits import WorkSpacesToolkit
# Configure the toolkit with your stack and application IDs
work_toolkit = WorkSpacesToolkit(
stack_id="your-stack-id",
application_id="your-application-id",
iam_role_arn="arn:aws:iam::123456789012:role/AgentWorkSpacesRole"
)
# Create a tool for the agent
work_tool = Tool(
name="DesktopApplication",
func=work_toolkit.run,
description="Useful for interacting with legacy desktop applications via WorkSpaces."
)
# Initialize agent
agent = initialize_agent(
tools=[work_tool],
llm=your_llm,
agent="zero-shot-react-description",
verbose=True
)
agent.run("Open the mainframe terminal and run quarterly report generation.")
For CrewAI, you would similarly define a WorkSpaces agent that can be called within a Crew. For Strands Agents, configure the MCP endpoint URL provided in the stack details.
5. Validate Audit Trails and Security
After deploying, monitor agent sessions via AWS CloudTrail (logs all API calls) and Amazon CloudWatch (application metrics).
- Enable CloudTrail for the WorkSpaces namespace.
- Set up CloudWatch dashboards to track session duration, errors, and resource usage.
- Verify that your existing security controls (e.g., VPC security groups, encryption at rest) apply to agent sessions.
Common Mistakes
- Missing VPC Endpoints – Agents cannot connect without at least one interface endpoint for WorkSpaces. Ensure you create them in the same VPC as the stack.
- Incorrect IAM Role – The role used by the agent must have
workSpaces:StartApplicationpermission. Also, ensure the trust policy allows the agent's principal to assume it. - No MCP Support in Agent Framework – Verify that your agent framework version supports MCP. For older LangChain releases, you may need to update.
- Overlooking Application Image – If the WorkSpaces bundle doesn't include the required legacy software, the agent won't see it. Pre-install all necessary applications.
- Not Testing with a Human User First – Always test the WorkSpace manually to confirm desktop applications work before giving access to an agent.
Summary
Amazon WorkSpaces now allows AI agents to securely operate legacy desktop applications without APIs or migrations. This guide covered creating a WorkSpaces Applications stack, configuring IAM permissions, and connecting agent frameworks via MCP. By following these steps, you can modernize your enterprise workflows while maintaining security and auditability. Start by reviewing the prerequisites and then build your first agent-enabled WorkSpace.
Related Discussions