Skip to content

Commit 44b0a33

Browse files
committed
inital commit of computer use
1 parent 9b528a4 commit 44b0a33

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+6452
-0
lines changed

computer-use/.gitignore

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
*.swp
2+
package-lock.json
3+
.pytest_cache
4+
*.egg-info
5+
6+
# Byte-compiled / optimized / DLL files
7+
__pycache__/
8+
*.py[cod]
9+
*$py.class
10+
11+
# Environments
12+
.env
13+
.venv
14+
env/
15+
venv/
16+
ENV/
17+
env.bak/
18+
venv.bak/
19+
20+
# CDK Context & Staging files
21+
.cdk.staging/
22+
cdk.out/
23+
cdk*.json
24+
cdk.*.json
25+
cdk.context.json
26+
# IDE specific files
27+
.idea/
28+
.vscode/
29+
*.sublime-workspace
30+
*.sublime-project
31+
32+
# OS specific files
33+
.DS_Store
34+
Thumbs.db

computer-use/README.md

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
# Computer Use AWS Infrastructure
2+
3+
This project contains the AWS CDK infrastructure code for deploying the Computer Use AWS application in the us-west-2 (Oregon) region. The infrastructure includes ECS Fargate services, ECR repositories, and all necessary networking components.
4+
5+
## Project Structure
6+
7+
```
8+
ComputerUseAWS/
9+
├── README.md
10+
├── app.py
11+
├── cdk.json
12+
├── computer_use_aws_stack.py
13+
├── requirements.txt
14+
├── scripts/
15+
│ └── get_urls.sh
16+
├── computer_use_aws/
17+
│ ├── environment_image/
18+
│ │ ├── computer_use_demo/
19+
│ │ ├── image/
20+
│ │ ├── Dockerfile
21+
│ │ └── requirements.txt
22+
│ └── orchestration_image/
23+
│ ├── computer_use_demo/
24+
│ ├── Dockerfile
25+
│ └── requirements.txt
26+
└── tests/
27+
├── integration/
28+
└── unit/
29+
```
30+
31+
## Prerequisites
32+
33+
1. AWS CLI installed and configured with us-west-2 region
34+
2. Python 3.7 or later
35+
3. Node.js 14.x or later (required for CDK)
36+
4. Docker installed and running
37+
5. AWS CDK CLI installed (`npm install -g aws-cdk`)
38+
39+
## Quick Start
40+
1. Clone the repository:
41+
```bash
42+
git clone git@ssh.gitlab.aws.dev:jonaevau/ComputerUseAWS.git
43+
cd ComputerUseAWS
44+
```
45+
46+
2. Make the gets_urls.sh cript executable:
47+
```bash
48+
chmod +x scripts/gets_urls.sh
49+
```
50+
51+
3. Configure AWS CLI for us-west-2 (if not already configured):
52+
```bash
53+
aws configure set default.region us-west-2
54+
```
55+
56+
4. Create virtual environment:
57+
```bash
58+
python -m venv .venv
59+
source .venv/bin/activate # On Windows use: .venv\Scripts\activate
60+
```
61+
62+
5. Install the required dependencies:
63+
```bash
64+
pip install -r requirements.txt
65+
```
66+
67+
6. Bootstrap CDK in us-west-2 (if you haven't already):
68+
```bash
69+
cdk bootstrap aws://ACCOUNT-NUMBER/us-west-2
70+
```
71+
72+
7. Deploy the solution in **Fail-Secure Mode** (Default). In this mode, if no IP address is provided, the security groups will default to a highly restrictive setting (255.255.255.255/32) that effectively blocks all access. This is the recommended setting for the sandbox environment.
73+
74+
```bash
75+
# Deploy with your current IP (Fail-Secure)
76+
cdk deploy --context deployer_ip=$(curl -s https://api.ipify.org)
77+
78+
# Deploy with manual IP (Fail-Secure)
79+
cdk deploy --context deployer_ip=203.0.113.1
80+
# This will automatically be converted to 203.0.113.1/32
81+
82+
# Deploy with IP address range (Fail-Secure)
83+
cdk deploy --context deployer_ip=203.0.113.0/24
84+
# Allows 203.0.113.0 through 203.0.113.255
85+
```
86+
87+
**Note**: This stack takes ~10-15 minutes to deploy. After the deployment it may take a few additional minutes for the Environment/Virtual Machine to come online
88+
89+
8. After the deploy has completed, you can cet the URLs of the services:
90+
```bash
91+
./scripts/get_urls.sh
92+
```
93+
94+
**Note**:If you are using aws profiles append --profile <profile name> to the command line if not provided "default" is assumed
95+
```bash
96+
./scripts/get_urls.sh --profile <your profile name>
97+
```
98+
99+
100+
## Usage
101+
102+
Navigate to the links provided in the output of the `get_urls.sh` script to access the services, the Orchestration Service URL and Environment Service URL.
103+
104+
The DCV **username** is `computeruse` and the **password** is `admin`. DCV is used to connect to the environment container for remote desktop access, for activities such as resetting the state of the environment, or elliciting the state of the environment prior to a new task.
105+
106+
The Streamlit interface is used to configure the API provider, model, and other parameters for the environment container. Then ultimately instruct the model via a chat interface to perform tasks.
107+
108+
## GUI Access
109+
110+
After navigating to the Orchestration Service URL (Streamlit interface), you'll need to log in:
111+
112+
1. Default credentials:
113+
- **Username:** `admin`
114+
- **Password:** `computeruse`
115+
116+
2. After successful login, you'll see:
117+
- Configuration panel in the sidebar
118+
- Chat interface in the main area
119+
- HTTP Exchange Logs tab for debugging
120+
121+
Note: The session will timeout after 60 minutes of inactivity, requiring you to log in again.
122+
123+
## Infrastructure Components
124+
125+
- **VPC**: Configured with public and private subnets across 2 AZs in us-west-2
126+
- **ECR Repository**: Single repository for both environment and orchestration images
127+
- **ECS Cluster**: Fargate cluster for running containers
128+
- **Task Definition**: Includes both containers with appropriate port mappings
129+
- **Security Groups**:
130+
- Environment container: Accepts traffic only from orchestration container
131+
- Orchestration container: Accepts public traffic on port 8501
132+
- **IAM Roles**: Task execution role with minimal permissions
133+
- **CloudWatch Logs**: Configured for container logging
134+
- **KMS**: Encryption key for secure storage
135+
136+
## Container Ports
137+
138+
- **Environment Container**:
139+
- 8443: DCV
140+
- 5000: Flask Control API
141+
- **Orchestration Container**:
142+
- 8501: Streamlit interface
143+
144+
## Monitoring
145+
146+
- Container insights enabled for the ECS cluster
147+
- CloudWatch logs configured with KMS encryption
148+
- VPC flow logs enabled for network monitoring
149+
- All logs retained for one month
150+
151+
## Troubleshooting
152+
153+
1. If deployment fails:
154+
```bash
155+
# Check AWS credentials
156+
aws sts get-caller-identity
157+
158+
# Check CloudFormation events
159+
aws cloudformation describe-stack-events --stack-name ComputerUseAwsStack
160+
```
161+
162+
2. If containers fail to start:
163+
```bash
164+
# Check ECS service events
165+
aws ecs describe-services --cluster computer-use-aws-cluster --services computer-use-aws-service-computeruseawsstack
166+
167+
# Check container logs
168+
aws logs get-log-events --log-group-name /ecs/computer-use-aws-computeruseawsstack
169+
```
170+
171+
## Clean Up
172+
173+
To destroy the infrastructure:
174+
```bash
175+
cdk destroy
176+
```

computer-use/app.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env python3
2+
import os
3+
import aws_cdk as cdk
4+
from computer_use_aws_stack import ComputerUseAwsStack
5+
6+
app = cdk.App()
7+
ComputerUseAwsStack(app, "ComputerUseAwsStack",
8+
env=cdk.Environment(
9+
account=os.getenv('CDK_DEFAULT_ACCOUNT'),
10+
region='us-west-2'
11+
),
12+
)
13+
14+
app.synth()

computer-use/computer_use_aws/__init__.py

Whitespace-only changes.
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
FROM public.ecr.aws/ubuntu/ubuntu:22.04
2+
3+
ENV DEBIAN_FRONTEND=noninteractive
4+
ENV DEBIAN_PRIORITY=high
5+
6+
RUN apt-get update && \
7+
apt-get -y upgrade && \
8+
apt-get -y install \
9+
build-essential \
10+
# UI Requirements
11+
xvfb \
12+
xterm \
13+
dbus \
14+
dbus-x11 \
15+
x11-xserver-utils \
16+
xdotool \
17+
scrot \
18+
imagemagick \
19+
sudo \
20+
mutter \
21+
x11vnc \
22+
# Python/pyenv reqs
23+
build-essential \
24+
libssl-dev \
25+
zlib1g-dev \
26+
libbz2-dev \
27+
libreadline-dev \
28+
libsqlite3-dev \
29+
curl \
30+
git \
31+
libncursesw5-dev \
32+
xz-utils \
33+
tk-dev \
34+
libxml2-dev \
35+
libxmlsec1-dev \
36+
libffi-dev \
37+
liblzma-dev \
38+
# Network tools
39+
net-tools \
40+
netcat \
41+
# PPA req
42+
software-properties-common && \
43+
# Userland apps
44+
sudo add-apt-repository ppa:mozillateam/ppa && \
45+
sudo apt-get install -y --no-install-recommends \
46+
libreoffice \
47+
firefox-esr \
48+
x11-apps \
49+
xpdf \
50+
gedit \
51+
xpaint \
52+
tint2 \
53+
galculator \
54+
pcmanfm \
55+
unzip && \
56+
apt-get clean
57+
58+
RUN apt-get install -y wget
59+
60+
# Install Amazon DCV
61+
RUN wget https://d1uj6qtbmh3dt5.cloudfront.net/NICE-GPG-KEY && \
62+
gpg --import NICE-GPG-KEY && \
63+
wget https://d1uj6qtbmh3dt5.cloudfront.net/2024.0/Servers/nice-dcv-2024.0-17979-ubuntu2204-aarch64.tgz && \
64+
tar -xvzf nice-dcv-2024.0-17979-ubuntu2204-aarch64.tgz && \
65+
cd nice-dcv-2024.0-17979-ubuntu2204-aarch64 && \
66+
apt install -y ./nice-dcv-server_2024.0.17979-1_arm64.ubuntu2204.deb && \
67+
apt install -y ./nice-dcv-web-viewer_2024.0.17979-1_arm64.ubuntu2204.deb && \
68+
cd .. && \
69+
rm -rf nice-dcv-2024.0-17979-ubuntu2204-aarch64*
70+
71+
# setup user
72+
ENV USERNAME=computeruse
73+
ENV HOME=/home/$USERNAME
74+
RUN useradd -m -s /bin/bash -d $HOME $USERNAME
75+
RUN echo "${USERNAME} ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
76+
RUN usermod -aG video $USERNAME
77+
78+
# Add after DCV installation and before switching to non-root user
79+
RUN mkdir -p /var/run/dcv && \
80+
mkdir -p /var/log/dcv && \
81+
chown -R $USERNAME:$USERNAME /var/run/dcv && \
82+
chown -R $USERNAME:$USERNAME /var/log/dcv && \
83+
chmod 755 /var/run/dcv && \
84+
chmod 755 /var/log/dcv && \
85+
mkdir -p /etc/dcv && \
86+
echo -e "[security]\nauthentication=none\n\n[display/linux]\ndisable-local-console=false" > /etc/dcv/dcv.conf && \
87+
echo "computeruse:admin" | chpasswd
88+
89+
# Copy the dbus config file to allow non-root users
90+
COPY --chown=root:root ./image/dbus.conf /etc/dbus-1/system.d/dcv-server.conf
91+
92+
USER computeruse
93+
WORKDIR $HOME
94+
95+
# setup python
96+
RUN git clone https://github.com/pyenv/pyenv.git ~/.pyenv && \
97+
cd ~/.pyenv && src/configure && make -C src && cd .. && \
98+
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc && \
99+
echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc && \
100+
echo 'eval "$(pyenv init -)"' >> ~/.bashrc
101+
ENV PYENV_ROOT="$HOME/.pyenv"
102+
ENV PATH="$PYENV_ROOT/bin:$PATH"
103+
ENV PYENV_VERSION_MAJOR=3
104+
ENV PYENV_VERSION_MINOR=11
105+
ENV PYENV_VERSION_PATCH=6
106+
ENV PYENV_VERSION=$PYENV_VERSION_MAJOR.$PYENV_VERSION_MINOR.$PYENV_VERSION_PATCH
107+
RUN eval "$(pyenv init -)" && \
108+
pyenv install $PYENV_VERSION && \
109+
pyenv global $PYENV_VERSION && \
110+
pyenv rehash
111+
ENV PATH="$HOME/.pyenv/shims:$HOME/.pyenv/bin:$PATH"
112+
RUN python -m pip install --upgrade pip==23.1.2 setuptools==58.0.4 wheel==0.40.0 && \
113+
python -m pip config set global.disable-pip-version-check true
114+
115+
# only reinstall if requirements.txt changes
116+
COPY --chown=$USERNAME:$USERNAME requirements.txt $HOME/computer_use_demo/requirements.txt
117+
RUN python -m pip install -r $HOME/computer_use_demo/requirements.txt
118+
119+
# setup desktop env & app
120+
COPY --chown=$USERNAME:$USERNAME image/ $HOME
121+
RUN chmod +x $HOME/entrypoint.sh $HOME/dvc_startup.sh
122+
COPY --chown=$USERNAME:$USERNAME computer_use_demo/ $HOME/computer_use_demo/
123+
ARG DISPLAY_NUM=1
124+
ARG HEIGHT=768
125+
ARG WIDTH=1024
126+
ENV DISPLAY_NUM=$DISPLAY_NUM
127+
ENV HEIGHT=$HEIGHT
128+
ENV WIDTH=$WIDTH
129+
130+
# Expose ports
131+
EXPOSE 5000
132+
EXPOSE 8443
133+
134+
ENTRYPOINT [ "./entrypoint.sh" ]
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from flask import Flask, request, jsonify
2+
from tools import BashTool, ComputerTool, EditTool, ToolCollection
3+
4+
app = Flask(__name__)
5+
6+
tool_collection = ToolCollection(
7+
ComputerTool(),
8+
BashTool(),
9+
EditTool(),
10+
)
11+
12+
@app.route('/execute', methods=['POST'])
13+
async def execute_tool():
14+
data = request.json
15+
tool_name = data.get('tool')
16+
tool_input = data.get('input')
17+
18+
if not tool_name or not tool_input:
19+
return jsonify({"error": "Missing tool name or input"}), 400
20+
21+
try:
22+
result = await tool_collection.run(name=tool_name, tool_input=tool_input)
23+
return jsonify({"result": result.to_dict()})
24+
except Exception as e:
25+
print(e)
26+
return jsonify({"error": str(e)}), 500
27+
28+
if __name__ == '__main__':
29+
app.run(host='0.0.0.0', port=5000)

0 commit comments

Comments
 (0)