Skip to content

Commit 5beefc6

Browse files
committed
feat: computer sandbox
1 parent c395b9e commit 5beefc6

25 files changed

+11527
-0
lines changed

docker/ai-desktop/.dockerignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Ignore files that shouldn't be in the Docker build context
2+
*.log
3+
*.tmp
4+
.git
5+
.gitignore

docker/ai-desktop/Dockerfile

Lines changed: 279 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,279 @@
1+
# AI-Controlled Desktop Environment
2+
FROM ubuntu:22.04
3+
4+
# Avoid prompts during package installation
5+
ENV DEBIAN_FRONTEND=noninteractive
6+
ENV DISPLAY=:1
7+
ENV VNC_PORT=5901
8+
ENV WEBSOCKET_PORT=6080
9+
ENV VNC_COL_DEPTH=24
10+
ENV VNC_RESOLUTION=1920x1080
11+
ENV LANG=en_US.UTF-8
12+
ENV LC_ALL=en_US.UTF-8
13+
14+
# Install base packages
15+
RUN apt-get update && apt-get install -y \
16+
wget \
17+
curl \
18+
sudo \
19+
git \
20+
vim \
21+
nano \
22+
htop \
23+
net-tools \
24+
iputils-ping \
25+
python3 \
26+
python3-pip \
27+
python3-dev \
28+
python3-tk \
29+
python3-pil \
30+
python3-pil.imagetk \
31+
nodejs \
32+
npm \
33+
build-essential \
34+
dos2unix \
35+
locales \
36+
&& locale-gen en_US.UTF-8 \
37+
&& apt-get clean \
38+
&& rm -rf /var/lib/apt/lists/*
39+
40+
# Install XFCE desktop environment and required tools
41+
RUN apt-get update && apt-get install -y \
42+
xfce4 \
43+
xfce4-terminal \
44+
xfce4-screenshooter \
45+
xfce4-taskmanager \
46+
xfce4-clipman-plugin \
47+
xfce4-cpugraph-plugin \
48+
xfce4-netload-plugin \
49+
xfce4-xkb-plugin \
50+
thunar \
51+
xfce4-settings \
52+
xfconf \
53+
libglib2.0-bin \
54+
attr \
55+
x11-xserver-utils \
56+
dbus-x11 \
57+
caffeine \
58+
&& apt-get clean \
59+
&& rm -rf /var/lib/apt/lists/*
60+
61+
# Install VNC server
62+
RUN apt-get update && apt-get install -y \
63+
tigervnc-standalone-server \
64+
tigervnc-common \
65+
&& apt-get clean \
66+
&& rm -rf /var/lib/apt/lists/*
67+
68+
# Install noVNC for web access
69+
RUN git clone https://github.com/novnc/noVNC.git /opt/novnc \
70+
&& git clone https://github.com/novnc/websockify.git /opt/novnc/utils/websockify \
71+
&& ln -s /opt/novnc/vnc.html /opt/novnc/index.html
72+
73+
# Install Chrome and its dependencies
74+
RUN apt-get update && apt-get install -y \
75+
wget \
76+
gnupg \
77+
&& wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | apt-key add - \
78+
&& echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list \
79+
&& apt-get update \
80+
&& apt-get install -y \
81+
google-chrome-stable \
82+
fonts-liberation \
83+
libasound2 \
84+
libatk-bridge2.0-0 \
85+
libatk1.0-0 \
86+
libatspi2.0-0 \
87+
libcups2 \
88+
libdbus-1-3 \
89+
libdrm2 \
90+
libgbm1 \
91+
libgtk-3-0 \
92+
libnspr4 \
93+
libnss3 \
94+
libxcomposite1 \
95+
libxdamage1 \
96+
libxfixes3 \
97+
libxkbcommon0 \
98+
libxrandr2 \
99+
xdg-utils \
100+
&& apt-get clean \
101+
&& rm -rf /var/lib/apt/lists/*
102+
103+
# Install screenshot and OCR support
104+
RUN apt-get update && apt-get install -y \
105+
scrot \
106+
imagemagick \
107+
gnome-screenshot \
108+
flameshot \
109+
xvfb \
110+
x11-apps \
111+
x11-utils \
112+
xdotool \
113+
wmctrl \
114+
tesseract-ocr \
115+
tesseract-ocr-eng \
116+
libtesseract-dev \
117+
python3-xlib \
118+
libx11-dev \
119+
libxext-dev \
120+
libxrender-dev \
121+
libxinerama-dev \
122+
libxi-dev \
123+
libxrandr-dev \
124+
libxcursor-dev \
125+
libxtst-dev \
126+
libxkbfile-dev \
127+
&& apt-get clean \
128+
&& rm -rf /var/lib/apt/lists/*
129+
130+
# Install Python packages for automation with anti-detection capabilities
131+
RUN pip3 install --no-cache-dir \
132+
pyautogui==0.9.54 \
133+
selenium==4.15.2 \
134+
undetected-chromedriver==3.5.4 \
135+
selenium-stealth==1.0.6 \
136+
fake-useragent==1.4.0 \
137+
playwright \
138+
playwright-stealth \
139+
opencv-python-headless==4.8.1.78 \
140+
Pillow>=9.2.0 \
141+
requests==2.31.0 \
142+
websocket-client==1.6.4 \
143+
websockets==12.0 \
144+
python-dotenv==1.0.0 \
145+
pynput==1.7.6 \
146+
pytesseract==0.3.10 \
147+
numpy==1.24.3 \
148+
python-xlib==0.33 \
149+
mss==9.0.1
150+
151+
# Install Playwright browsers (Chrome only)
152+
RUN playwright install chromium
153+
154+
# Install Chrome WebDriver for Selenium
155+
RUN apt-get update && apt-get install -y \
156+
chromium-chromedriver \
157+
&& ln -s /usr/bin/chromedriver /usr/local/bin/chromedriver \
158+
&& apt-get clean \
159+
&& rm -rf /var/lib/apt/lists/*
160+
161+
# Create user with proper groups for Chrome
162+
RUN useradd -m -s /bin/bash desktop && \
163+
echo "desktop:desktop" | chpasswd && \
164+
usermod -aG sudo,audio,video desktop
165+
166+
# Set up Chrome sandbox requirements and profile directories
167+
RUN mkdir -p /opt/google/chrome && \
168+
chown root:root /opt/google/chrome && \
169+
chmod 4755 /opt/google/chrome && \
170+
mkdir -p /home/desktop/.config/google-chrome && \
171+
mkdir -p /home/desktop/.config/google-chrome-docker && \
172+
mkdir -p /home/desktop/.config/google-chrome-docker/Default && \
173+
mkdir -p /home/desktop/.config/chromium && \
174+
mkdir -p /etc/opt/chrome/policies/managed && \
175+
mkdir -p /etc/chromium/policies/managed && \
176+
chown -R desktop:desktop /home/desktop/.config && \
177+
chmod -R 755 /home/desktop/.config
178+
179+
# Create secure directories
180+
RUN mkdir -p /opt/.system && chmod 700 /opt/.system && \
181+
mkdir -p /opt/.ai_core && chmod 700 /opt/.ai_core && \
182+
mkdir -p /opt/ai_agent && chmod 700 /opt/ai_agent && chown root:root /opt/ai_agent
183+
184+
# Copy and compile Python files in a secure way
185+
COPY ai_agent_server.py /tmp/ai_agent_server.py
186+
COPY stealth_browser.py /tmp/stealth_browser.py
187+
COPY test_imports.py /tmp/test_imports.py
188+
COPY test_anti_detection.py /tmp/test_anti_detection.py
189+
RUN cd /tmp && \
190+
python3 -O -m py_compile ai_agent_server.py stealth_browser.py test_imports.py test_anti_detection.py && \
191+
mv __pycache__/*.pyc /opt/.ai_core/ && \
192+
chmod 400 /opt/.ai_core/*.pyc && \
193+
chown root:root /opt/.ai_core/*.pyc && \
194+
rm -rf /tmp/*.py /tmp/__pycache__
195+
196+
# Copy startup scripts with security
197+
COPY --chmod=700 startup.sh /opt/.system/startup.sh
198+
COPY --chmod=700 startup.azure.sh /opt/.system/startup.azure.sh
199+
COPY --chmod=700 entrypoint.sh /opt/.system/entrypoint.sh
200+
COPY --chmod=700 security-hardening.sh /opt/.system/security-hardening.sh
201+
COPY --chmod=755 display_recovery.sh /opt/.system/display_recovery.sh
202+
COPY --chmod=755 vnc_startup.sh /vnc_startup.sh
203+
COPY --chmod=755 novnc-config.sh /novnc-config.sh
204+
COPY --chmod=755 xstartup /opt/xstartup
205+
COPY --chmod=755 keep-screen-alive.sh /opt/keep-screen-alive.sh
206+
COPY requirements.txt /opt/.ai_core/requirements.txt
207+
COPY --chmod=700 start_agent.sh /opt/.ai_core/start_agent.sh
208+
COPY --chmod=755 chrome-wrapper.sh /usr/local/bin/chrome-wrapper
209+
COPY --chmod=755 chrome-auth-wrapper.sh /usr/local/bin/chrome-auth-wrapper
210+
COPY chrome-policies.json /etc/opt/chrome/policies/managed/chrome-policies.json
211+
COPY chrome-policies.json /etc/chromium/policies/managed/chrome-policies.json
212+
COPY master_preferences /opt/google/chrome/master_preferences
213+
COPY master_preferences /usr/share/google-chrome/master_preferences
214+
COPY master_preferences /home/desktop/.config/google-chrome-docker/Default/Preferences
215+
RUN chown desktop:desktop /home/desktop/.config/google-chrome-docker/Default/Preferences && \
216+
chmod 644 /home/desktop/.config/google-chrome-docker/Default/Preferences && \
217+
chown -R desktop:desktop /home/desktop/.config/google-chrome-docker
218+
219+
# Fix line endings for all scripts (critical for proper execution)
220+
RUN dos2unix /opt/.system/startup.sh /opt/.system/startup.azure.sh /opt/.system/entrypoint.sh \
221+
/opt/.system/security-hardening.sh /opt/.system/display_recovery.sh /vnc_startup.sh /novnc-config.sh /opt/xstartup \
222+
/opt/keep-screen-alive.sh /opt/.ai_core/start_agent.sh /usr/local/bin/chrome-wrapper /usr/local/bin/chrome-auth-wrapper 2>/dev/null || true && \
223+
chmod +x /opt/.system/startup.sh /opt/.system/startup.azure.sh /opt/.system/entrypoint.sh \
224+
/opt/.system/security-hardening.sh /opt/.system/display_recovery.sh /vnc_startup.sh /novnc-config.sh /opt/xstartup \
225+
/opt/keep-screen-alive.sh /opt/.ai_core/start_agent.sh /usr/local/bin/chrome-wrapper /usr/local/bin/chrome-auth-wrapper
226+
227+
# Create secure wrapper for AI agent
228+
RUN echo '#!/bin/bash' > /opt/.ai_core/run.sh && \
229+
echo 'cd /opt/.ai_core' >> /opt/.ai_core/run.sh && \
230+
echo 'export DISPLAY=:1' >> /opt/.ai_core/run.sh && \
231+
echo 'export XAUTHORITY=/root/.Xauthority' >> /opt/.ai_core/run.sh && \
232+
echo 'export PYAUTOGUI_FAILSAFE=0' >> /opt/.ai_core/run.sh && \
233+
echo 'python3 ai_agent_server.cpython-310.opt-1.pyc 2>&1' >> /opt/.ai_core/run.sh && \
234+
chmod 700 /opt/.ai_core/run.sh && \
235+
chown root:root /opt/.ai_core/run.sh
236+
237+
# Install AI agent dependencies and setup logging
238+
WORKDIR /opt/.ai_core
239+
RUN pip3 install -r requirements.txt && \
240+
# Create log directory with proper permissions
241+
mkdir -p /var/log && \
242+
touch /var/log/ai_agent.log && \
243+
chmod 666 /var/log/ai_agent.log && \
244+
chown desktop:desktop /var/log/ai_agent.log && \
245+
# Remove the old ai_agent directory if it exists
246+
rm -rf /opt/ai_agent
247+
248+
# Also copy the Python source files for fallback imports
249+
COPY ai_agent_server.py /opt/.ai_core/ai_agent_server.py
250+
COPY stealth_browser.py /opt/.ai_core/stealth_browser.py
251+
COPY test_anti_detection.py /opt/.ai_core/test_anti_detection.py
252+
RUN chmod 644 /opt/.ai_core/*.py && \
253+
chown root:root /opt/.ai_core/*.py
254+
255+
# Set up VNC directory as desktop user
256+
USER desktop
257+
RUN mkdir -p /home/desktop/.vnc && \
258+
mkdir -p /home/desktop/Desktop && \
259+
mkdir -p /home/desktop/.config/autostart && \
260+
touch "/home/desktop/.config/google-chrome-docker/First Run"
261+
262+
# Add aliases for easy command line access
263+
RUN echo "alias chrome='/usr/local/bin/chrome-wrapper'" >> /home/desktop/.bashrc && \
264+
echo "alias google-chrome='/usr/local/bin/chrome-wrapper'" >> /home/desktop/.bashrc && \
265+
echo "alias chrome-auth='/usr/local/bin/chrome-auth-wrapper'" >> /home/desktop/.bashrc
266+
267+
USER root
268+
269+
# Expose ports (VNC, noVNC, SSH, AI Agent WebSocket, Chrome DevTools)
270+
EXPOSE 5901 6080 22 8080 9222
271+
272+
# Ensure startup script runs as root (it will switch to desktop user internally)
273+
WORKDIR /home/desktop
274+
275+
# Set environment variable for Azure detection (optional, can be set at runtime)
276+
ENV AZURE_CONTAINER_INSTANCE=""
277+
278+
# Start services with entrypoint that detects environment
279+
ENTRYPOINT ["/bin/bash", "/opt/.system/entrypoint.sh"]

0 commit comments

Comments
 (0)