# Always run LLM code in a Sandbox

> Source: <https://jimmyislive.dev/posts/llm-sandbox/>
> Published: 2026-12-05 00:00:00+00:00

**Recommendation:** Execute LLM-generated code in a disposable microVM or Claude's sandbox rather than your local environment, and require approval for commands, because a poisoned model could exfiltrate session credentials.
More in the playbook "Securing agents and AI tools": <https://wpnews.pro/playbooks/agent-security>

on

# Always run LLM code in a Sandbox

The biggest use of AI will be in offensive and defensive attacks. With the explosion of recent attacks secure practices is no longer optional.

One unlooked vector is that we trust our models way too much ! With the increasing popularity of open source models, it is just a matter of time before a popular open source model is poison pilled. What happens when an LLM *seems* to be useful but also has a backdoor that is exfiltrating crentials from your session ? The result will not be pretty.

Getting into a habit of putting some safeguards while executing LLMs is prudent. Here are some ways to do that.

# Sandboxing in Claude

If you use claude, a easy way is to sandbox it via the [`/sandbox`](https://code.claude.com/docs/en/settings-reference#sandbox-enabled) command. It runs all bash commands within a sandbox and cannot access directories outside of the current working directory. That along with always [requiring approval](https://code.claude.com/docs/en/permissions) for commands provides some layer of protection.

Better still, add it to your `~/.claude/settings.json` file, so it happens by default:

```
    "sandbox": {
        "enabled": true
    }
```

NOTE: This is not foolproof sandboxing. There are [many things](https://code.claude.com/docs/en/sandboxing#what-runs-outside-the-sandbox) that still run outside the sandbox.

# Sandboxing via a microVM

A much betterway would be to always run LLM generated code inside a microVM. These are use and throw and would never touch your localdev. e.g. lets say you want to write code to parse some log files and generate stats for the amount of data parsed, number of errors, info, debug lines etc. I used a microVM provider called [E2B](https://e2b.dev) to run it and provide me the result:

```
pip3 install e2b anthropic
export E2B_API_KEY=...  ANTHROPIC_API_KEY=...
python e2b_log_parser.py messy_app.log answer_key.json
```

`The actual code is not important here. Just ask your LLM to generate similar sample code.`

The python code essentialy used the e2b sdk, fired up a microVM in the cloud, generated code, executed it, did this in a loop until it got it right, then terminated the microVM. All without running anything on my local environment.

There are many other ways to leverage microVMs and I would encourage everyone to start looking at such security practices by default.

It’s ok to be paranoid !
