You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit fd6e23c
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: blog/2026-10-03-ubuntu-vm-in-virtualbox-for-claude-code/index.md
+56-1Lines changed: 56 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -274,6 +274,60 @@ gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-ac-type 'no
274
274
275
275
Running it inside `tmux` has a second benefit: `tmux attach -t claude` shows the live session in a terminal, for example to confirm the first-run prompts. Detach again with `Ctrl+B`, then `D`.
276
276
277
+
## Add a swap file
278
+
279
+
4 GB of RAM is not much for a GNOME desktop plus Claude Code plus whatever the agent builds or tests. When memory runs out, the kernel kills a process - often the build, sometimes the session itself. A swap file gives it room to breathe. Check first what is there:
280
+
281
+
```bash
282
+
swapon --show
283
+
free -h
284
+
```
285
+
286
+
An 8 GB swap file on the ext4 root disk:
287
+
288
+
```bash
289
+
sudo swapoff -a # in case /swapfile exists and is in use
290
+
sudo fallocate -l 8G /swapfile
291
+
sudo chmod 600 /swapfile
292
+
sudo mkswap /swapfile
293
+
sudo swapon /swapfile
294
+
```
295
+
296
+
To activate it at every boot it needs a line in `/etc/fstab`. Add it only if it is not there yet:
297
+
298
+
```bash
299
+
grep -q '^/swapfile ' /etc/fstab ||echo'/swapfile none swap sw 0 0'| sudo tee -a /etc/fstab
300
+
```
301
+
302
+
After that `swapon --show` lists `/swapfile` with 8G. Inside the VM the 8 GB are reserved right away. The `.vdi` on the host only grows as swap is actually written.
303
+
304
+
Swap is a safety net, not more memory: once the VM swaps heavily it gets slow. If that happens regularly, give the VM more RAM instead (`VBoxManage modifyvm ClaudeAgent --memory 6144` while it is powered off).
305
+
306
+
## Let the agent use sudo
307
+
308
+
Installing a package or restarting a service needs `sudo`, and `sudo` asks for a password. A session driven from the phone has no terminal to type it into, so the command just fails with `sudo: a terminal is required to read the password`.
309
+
310
+
In this VM the agent may use `sudo` without a password. The rule goes into its own file below `/etc/sudoers.d`, written through `visudo` so that a typo cannot lock `sudo` up:
This asks for the password one last time. `visudo` checks the syntax before it saves; `0440` is the file mode `/etc/sudoers.d/README` asks for. Check the result with:
318
+
319
+
```bash
320
+
sudo -k # forget the cached password
321
+
sudo -n true&&echo"passwordless sudo works"
322
+
sudo -l # lists "(ALL) NOPASSWD: ALL"
323
+
```
324
+
325
+
The file name matters: files in `/etc/sudoers.d` are read in alphabetical order and the last matching rule wins, so `90-...` comes after the default `%sudo ALL=(ALL:ALL) ALL` rule from `/etc/sudoers`.
326
+
327
+
This makes the agent root in the VM - which is the reason for giving it a VM of its own. Do not do this on a machine that holds anything you care about. Claude Code's own permission prompts stay in place: it still asks before it runs a `sudo` command, unless the permission mode or an allow rule covers it.
328
+
329
+
To take it back, delete the file: `sudo rm /etc/sudoers.d/90-stefan-nopasswd`.
330
+
277
331
## Start the VM with Windows
278
332
279
333
To start the VM in the background at every Windows logon:
@@ -289,8 +343,9 @@ Remove the task again with `schtasks /Delete /TN "ClaudeAgent VM"`.
289
343
## What to keep in mind
290
344
291
345
-**Memory:** the VM reserves its 4 GB while it runs. On a 16 GB host that is noticeable; during the install my host ran critically low on free memory.
292
-
-**Disk:** the dynamic disk grows up to 60 GB. Keep an eye on free space on the host.
346
+
-**Disk:** the dynamic disk grows up to 60 GB, and the swap file can account for 8 GB of it. Keep an eye on free space on the host.
293
347
-**Speed:** with Hyper-V active on the host, the VM runs in the slower fallback mode. It works, but it is not fast.
348
+
-**Root in the VM:** with passwordless `sudo` the agent can change anything inside the VM. Shared folders and the bidirectional clipboard are the paths back to the host - keep them as narrow as you need them.
294
349
-**Host must stay awake:** if Windows sleeps, the VM and the session are gone until it wakes up.
295
350
296
351
For questions or feedback, contact us at [Codeuctivity@gmail.com](mailto:Codeuctivity@gmail.com).
0 commit comments