# Is a Dev Container Enough for an Untrusted Repo?

> Not on its own. By default a VS Code dev container mounts your workspace, reuses your Git credentials, forwards your SSH agent, copies your .gitconfig and shares your machine's kernel, and the repo's own devcontainer.json can run commands on your host. Turn those off, or open take-home repos in a no-env VM instead.

Source: https://sandboxer.com/guides/is-a-dev-container-enough-for-an-untrusted-repo. Updated 2026-11-25.

**Short answer:** Not on its own. By default a VS Code dev container mounts your workspace, reuses your Git credentials, forwards your SSH agent, copies your .gitconfig and shares your machine's kernel, and the repo's own devcontainer.json can run commands on your host. Turn those off, or open take-home repos in a no-env VM instead.

Part of [Best ways to run untrusted or LLM-generated code safely](/guides/best-ways-to-run-untrusted-code-safely).

A "take-home task" repo from a stranger is code you are asked to install and run. Its `npm install`, `pip install` or setup script runs with whatever the environment hands it. A dev container blocks a lot: the code runs in a container, not straight on your laptop. This page lists what still gets through, according to the VS Code and Docker docs, then runs a credential sniffer on prod to show what a clean VM exposes instead. To check a repo's README claims step by step, see [Check what an unknown GitHub repo really does](/guides/try-an-unknown-github-repo-safely-in-a-sandbox). For untrusted Python snippets, see [Run untrusted Python safely](/guides/run-untrusted-python-safely).

## What a dev container shares with your machine

| What is shared | What the docs say | What hostile code in the repo gets |
| - | - | - |
| Your workspace folder | "Workspace files are mounted from the local file system or copied or cloned into the container" ([VS Code](https://code.visualstudio.com/docs/devcontainers/containers)) | Write access to the folder on your disk, including `.git/hooks` and `.vscode` files you may run later |
| Git credentials | With a local credential helper, "Credentials you've entered locally will be reused in the container and vice versa" ([VS Code](https://code.visualstudio.com/remote/advancedcontainers/sharing-git-credentials)) | Your Git host login, through the helper |
| SSH agent | "the extension will automatically forward your local SSH agent if one is running" (same page) | Use of every key loaded in your agent while the container runs |
| `.gitconfig` | "The extension will automatically copy your local .gitconfig file into the container on startup" (same page) | Your name, email and any settings or tokens you keep in it |
| GPG keys, if you set it up | "you can share your local keys with your container as well" (same page) | Signing as you |
| Forwarded ports | Forwarded ports "actually look like localhost to the application" ([VS Code](https://code.visualstudio.com/docs/devcontainers/containers)) | A server reachable from your machine as `localhost` |
| Docker socket (docker-outside-of-docker) | The Feature will "Re-use the host docker socket", expected at `/var/run/docker.sock` on the host ([devcontainers/features](https://github.com/devcontainers/features/tree/main/src/docker-outside-of-docker)) | Your host's Docker daemon, which "requires root privileges unless you opt-in to Rootless mode" ([Docker](https://docs.docker.com/engine/security/)) |
| The kernel | "every container on a machine shares that machine's kernel" ([Docker](https://docs.docker.com/get-started/docker-concepts/the-basics/what-is-a-container/)) | One kernel bug away from the host |
| `initializeCommand` | Runs "on the host machine during initialization" ([devcontainer.json reference](https://containers.dev/implementors/json_reference/)) | A command on your laptop, outside the container |
| UI extensions | Themes, snippets and other UI extensions "are installed locally"; `"ui"` forces an extension "to run on the local UI/client side" ([VS Code](https://code.visualstudio.com/docs/devcontainers/containers)) | Extension code on your machine, not in the container |

Last checked: 2026-11-25, on prod (the sniffer run below); docs read the same day.

The column that matters most for a take-home repo is the last one, because the repo ships its own `.devcontainer/devcontainer.json`. The person who sent it chooses the `initializeCommand`, the `mounts` (they take "the same values as the Docker CLI `--mount` flag"), the Features and `privileged`. Docker's docs say a container with your `/` mounted at `/host` "can alter your host filesystem without any restriction." Workspace Trust is the guard VS Code gives you: it "lets you decide whether your project folders should allow or restrict automatic code execution", and reopening a folder in a container "requires trusting the local (or WSL) folder."

## The sniffer test, on prod

To see what a clean VM exposes, we wrote a harmless "credential sniffer" as an npm `postinstall` script: the hook a fake take-home repo would use. It prints names and paths only, never values. It looks for environment variables matching `TOKEN|KEY|SECRET`, SSH keys and an SSH agent, Git config and credential files, `~/.aws`, a Docker socket, a private address, the metadata address and the public internet.

```bash
#!/bin/bash
# sniff.sh: what a malicious postinstall would look for. Prints names and paths, never values.
echo "env names: $(env | cut -d= -f1 | grep -E 'TOKEN|KEY|SECRET' | sort | paste -sd' ' -)"
echo "ssh keys: $(ls ~/.ssh/id_* 2>/dev/null | paste -sd' ' - || true)"; echo "ssh agent: ${SSH_AUTH_SOCK:-none}"
echo "gitconfig: $(git config --global --list 2>/dev/null | cut -d= -f1 | paste -sd' ' -)"
echo "git creds: $(ls ~/.git-credentials ~/.config/gh/hosts.yml 2>/dev/null | paste -sd' ' -)"
echo "aws: $(ls -A ~/.aws 2>/dev/null | paste -sd' ' -)"
for s in /var/run/docker.sock /var/run/docker-host.sock; do
  [ -S "$s" ] && echo "docker socket: $s ($(stat -c '%U:%G %a' $s)); docker ps works: $(docker ps >/dev/null 2>&1 && echo yes || echo no)"
done
for u in http://10.0.0.1 http://169.254.169.254/latest/meta-data/ https://example.com; do
  code=$(curl -s -m 4 -o /dev/null -w '%{http_code}' "$u"); echo "reach $u: curl exit $? http $code"
done
```

```json
{ "name": "take-home-task", "version": "1.0.0", "scripts": { "postinstall": "bash sniff.sh" } }
```

We created a `small` sandbox with `--no-env`, copied both files in with `sbx scp`, and ran `npm install --foreground-scripts`, just as the "task" would ask you to:

```text
> take-home-task@1.0.0 postinstall
> bash sniff.sh

env names: SANDBOXER_TOKEN
ssh keys: 
ssh agent: none
gitconfig: 
git creds: 
aws: 
docker socket: /var/run/docker.sock (root:docker 660); docker ps works: yes
reach http://10.0.0.1: curl exit 28 http 000
reach http://169.254.169.254/latest/meta-data/: curl exit 28 http 000
reach https://example.com: curl exit 0 http 200
```

The install took 8.8 seconds. What each line means:

| Check | Found | Why |
| - | - | - |
| Env names | `SANDBOXER_TOKEN` only | `--no-env` passes none of your variables. That token is the sandbox's own, for reading that sandbox and hosting its ports ([environments](/docs/environments)). To hide it from the install too, start it with `env -i`, as the [Python guide](/guides/run-untrusted-python-safely) does |
| SSH keys, agent | None | Nothing is forwarded from your machine |
| `.gitconfig`, Git and `gh` credentials, `~/.aws` | None | Nothing is copied in |
| Docker socket | Yes, and `docker ps` works | This is the VM's own Docker. A `docker run -v /:/host` in the same sandbox saw the sandbox's hostname and its one `user` home: root inside the VM, not on your laptop |
| `10.0.0.1`, `169.254.169.254` | Timed out (curl exit 28) | Sandboxes can't reach private ranges or internal networks ([security](/docs/security)) |
| Public internet | HTTP 200 | Outbound is open by default. Code can still send out anything inside the VM |

The Docker row is the difference from a dev container in one line. In docker-outside-of-docker, the same `docker run -v /:/host` reaches your host's daemon and whatever that daemon can mount, which on a Linux host is your whole disk. In a VM, it reaches only the VM.

## How to lock a dev container down further

If you keep using a dev container for strangers' repos, close what the table above opens:

1. **Read `.devcontainer/` before you open it.** Look for `initializeCommand`, `mounts`, `runArgs`, `privileged` and Features such as docker-outside-of-docker. All of them are set by the repo ([devcontainer.json reference](https://containers.dev/implementors/json_reference/)).
2. **Don't trust the folder.** Keep it in Restricted Mode until you've read it ([Workspace Trust](https://code.visualstudio.com/docs/editor/workspace-trust)). Reopening in a container asks you to trust it; say no for a repo you haven't read.
3. **Don't forward your SSH agent.** The extension forwards it "if one is running", and the docs list no switch for it. Stop the agent, or remove its keys with `ssh-add -D`, before you open the repo.
4. **Use a dedicated account, not your login.** Credentials and `.gitconfig` are shared automatically. Open the repo from a separate OS user or machine with no Git logins, and give it a fine-grained token for one repo if it needs one.
5. **No Docker socket.** Don't add docker-outside-of-docker. Docker's docs: "only trusted users should be allowed to control your Docker daemon." If the task needs Docker, [Rootless mode](https://docs.docker.com/engine/security/rootless/) runs the daemon as a non-root user.
6. **Clone into a volume, not a bind mount.** "Repository Containers use isolated, local Docker volumes instead of binding to the local filesystem" ([VS Code](https://code.visualstudio.com/docs/devcontainers/containers)). Your local folder stays untouched, though the kernel is still shared.
7. **Cut the network for steps that don't need it**, so whatever the code finds can't leave. The [outbound allowlist guide](/guides/allowlist-an-agents-outbound-network-in-a-sandbox) shows one way.

Items 1 to 6 still leave the shared kernel. Only a VM removes that.

## Where Sandboxer fits

Each Sandboxer sandbox is a microVM with its own kernel, so a take-home repo runs on a separate machine rather than in a container on yours ([machines](/docs/machines)). Create it with `--no-env` and it holds none of your variables, files or credentials, which is what the sniffer saw. You can still open it in VS Code with Remote-SSH ([SSH docs](/docs/ssh)) and delete it when the interview is over. Plans start at $20/mo ([pricing](/pricing)).

## Copy-paste: run the credential sniffer in a no-env sandbox

After `curl -fsSL https://sandboxer.com/install | sh` and `sbx login`, this writes the sniffer and a fake `package.json`, runs `npm install` in a fresh `--no-env` sandbox and deletes it:

```bash
mkdir -p take-home && cd take-home
cat > sniff.sh <<'EOF'
#!/bin/bash
# sniff.sh: what a malicious postinstall would look for. Prints names and paths, never values.
echo "env names: $(env | cut -d= -f1 | grep -E 'TOKEN|KEY|SECRET' | sort | paste -sd' ' -)"
echo "ssh keys: $(ls ~/.ssh/id_* 2>/dev/null | paste -sd' ' - || true)"; echo "ssh agent: ${SSH_AUTH_SOCK:-none}"
echo "gitconfig: $(git config --global --list 2>/dev/null | cut -d= -f1 | paste -sd' ' -)"
echo "git creds: $(ls ~/.git-credentials ~/.config/gh/hosts.yml 2>/dev/null | paste -sd' ' -)"
echo "aws: $(ls -A ~/.aws 2>/dev/null | paste -sd' ' -)"
for s in /var/run/docker.sock /var/run/docker-host.sock; do
  [ -S "$s" ] && echo "docker socket: $s ($(stat -c '%U:%G %a' $s)); docker ps works: $(docker ps >/dev/null 2>&1 && echo yes || echo no)"
done
for u in http://10.0.0.1 http://169.254.169.254/latest/meta-data/ https://example.com; do
  code=$(curl -s -m 4 -o /dev/null -w '%{http_code}' "$u"); echo "reach $u: curl exit $? http $code"
done
EOF
echo '{"name":"take-home-task","version":"1.0.0","scripts":{"postinstall":"bash sniff.sh"}}' > package.json
id=$(sbx --json new --name sniff-test --type small --ttl 1800 --no-env | jq -r 'select(.event=="ready") | .id')
sbx exec "$id" "mkdir -p ~/take-home"
sbx scp sniff.sh "$id:/home/user/take-home/sniff.sh" && sbx scp package.json "$id:/home/user/take-home/package.json"
sbx exec "$id" --timeout 120 "cd ~/take-home && npm install --foreground-scripts --no-audit --no-fund 2>&1 | grep -v '^npm notice'"
sbx delete "$id" --yes >/dev/null && echo "deleted $id"
```

Our run on 2026-11-25:

```text
> take-home-task@1.0.0 postinstall
> bash sniff.sh

env names: SANDBOXER_TOKEN
ssh keys: 
ssh agent: none
gitconfig: 
git creds: 
aws: 
docker socket: /var/run/docker.sock (root:docker 660); docker ps works: yes
reach http://10.0.0.1: curl exit 28 http 000
reach http://169.254.169.254/latest/meta-data/: curl exit 28 http 000
reach https://example.com: curl exit 0 http 200

up to date in 10s
deleted sb_6y0fc5b1yc
```

Run the same `sniff.sh` inside your own dev container to compare. Expect an `SSH_AUTH_SOCK` path if your agent is running, your `.gitconfig` keys, and a Docker socket if the repo added docker-outside-of-docker.

## FAQ

### Is Workspace Trust enough on its own?

It stops automatic code execution until you trust the folder. Once you reopen the repo in its container, you have trusted it, and the repo's `initializeCommand`, mounts and install scripts run.

### Does a dev container protect my files outside the project?

The workspace folder is mounted, and the repo's `devcontainer.json` can add more mounts. Read it first, or clone into a container volume so even the project folder isn't your local one.

### Is a remote dev container on a cloud VM safer?

It moves the shared kernel off your laptop. Run the same `sniff.sh` in that container to see which of your credentials, keys and config still reach it before you trust it.

### What if the task needs my GitHub account?

Give it a fine-grained token for that one repo, passed with `-e`, and revoke it after. The [secrets guide](/guides/pass-secrets-to-a-sandbox-safely) shows how to pass one without leaving it in a command line.

## Related

- [Best ways to run untrusted or LLM-generated code safely](/guides/best-ways-to-run-untrusted-code-safely)
- [How do I check what an unknown GitHub repo really does, safely?](/guides/try-an-unknown-github-repo-safely-in-a-sandbox)
- [Keep API keys out of an agent sandbox](/guides/keep-api-keys-out-of-an-agent-sandbox)
- [Container vs microVM for untrusted code](/guides/container-vs-microvm-for-untrusted-code)
