Skip to content

Commit fd6e23c

Browse files
authored
Merge pull request #283 from Codeuctivity/blog-vm-post-agent-sudo
Blog: document swap file and passwordless sudo in VM post
2 parents 1f8ed16 + 7b3d9a6 commit fd6e23c

1 file changed

Lines changed: 56 additions & 1 deletion

File tree

  • blog/2026-10-03-ubuntu-vm-in-virtualbox-for-claude-code

‎blog/2026-10-03-ubuntu-vm-in-virtualbox-for-claude-code/index.md‎

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,60 @@ gsettings set org.gnome.settings-daemon.plugins.power sleep-inactive-ac-type 'no
274274

275275
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`.
276276

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:
311+
312+
```bash
313+
echo 'stefan ALL=(ALL) NOPASSWD: ALL' | sudo EDITOR='tee' visudo -f /etc/sudoers.d/90-stefan-nopasswd
314+
sudo chmod 0440 /etc/sudoers.d/90-stefan-nopasswd
315+
```
316+
317+
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+
277331
## Start the VM with Windows
278332

279333
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"`.
289343
## What to keep in mind
290344

291345
- **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.
293347
- **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.
294349
- **Host must stay awake:** if Windows sleeps, the VM and the session are gone until it wakes up.
295350

296351
For questions or feedback, contact us at [Codeuctivity@gmail.com](mailto:Codeuctivity@gmail.com).

0 commit comments

Comments
 (0)