keepcalculator

06 Numbers and Powers

Run AI Agents in a Sandbox Without Exposing Main Files

Card No. 06·17898 · Updated · Standard formula, shown below

Running an AI agent in a sandbox gives it a separate workspace where it can read and change project files without automatically granting access to your personal folders. The safest practical approach is to use an isolated virtual machine or container, provide only a copy of the files it needs, and limit network access and credentials.

What You’ll Need

  • A computer with a virtualization tool or a container runtime installed. A virtual machine generally offers stronger separation; containers are lighter but share the host operating-system kernel.
  • The agent software and any required runtime, installed inside the isolated environment rather than given broad access to your host.
  • A dedicated test project or disposable copy of the files the agent needs. Avoid using your home folder or main working directory as the sandbox workspace.
  • Time to check the sandbox’s shared-folder, network, clipboard, and device settings before starting.

Step-by-Step

  1. Choose the isolation level. For an agent that may run unknown scripts or install packages, use a virtual machine (VM) with a separate guest operating system. For routine work with trusted tools, a container can be convenient, but it is not equivalent to a separate machine: a container escape or a dangerous host mount can expose host data. Do not treat a container as a security boundary against a determined attacker.
  2. Create a fresh environment. Set up a new VM or container from a maintained operating-system image. Install only the tools the task requires. Keep the host and guest software updated, and avoid installing the agent in an environment that already contains personal documents, browser profiles, SSH keys, or cloud credentials.
  3. Make a clean workspace copy. Copy the specific project files into a new folder intended for the sandbox. Remove secrets first: check for configuration files, environment files, access tokens, private keys, database exports, and personal data. If the agent only needs sample data, use synthetic or redacted files. Do not mount your entire home directory or main drive.
  4. Review file-sharing settings. In a VM, disable shared folders unless they are essential. If you must share files, share only the dedicated input folder, preferably read-only, and use a separate output folder for results. Turn off automatic host-to-guest folder sharing, drag-and-drop, and clipboard sharing where the virtualization software offers those controls. In a container, do not mount sensitive host paths; use a narrow project mount and make it read-only when edits are unnecessary.
  5. Limit network access. Start with networking disabled if the job is offline. If the agent needs downloads or an API, allow only the access required through the environment’s network controls or a controlled proxy. Do not assume that a prompt telling an agent not to send data is a network restriction. Avoid signing into personal accounts or placing long-lived credentials in the sandbox; if access is unavoidable, use narrowly scoped, revocable credentials and remove them afterward.
  6. Set resource and device limits. Give the guest only the CPU, memory, storage, and devices needed for the task. Do not pass through cameras, microphones, USB devices, or the host’s container-management socket unless there is a clear need. A container with access to a powerful host control socket may be able to control the host, so do not expose it casually.
  7. Install and configure the agent inside the sandbox. Follow the software’s documented installation instructions in the guest. Configure its working directory to the copied project, not a broad filesystem location. Check any file-access, command-execution, approval, or tool permissions it provides. Prefer confirmation before destructive actions, but treat these controls as an extra layer, not a substitute for isolation.
  8. Test the boundary with harmless checks. Ask the agent to list files in its workspace and confirm that only the intended project appears. Check that it cannot see your personal folders, keys, or unrelated host files. Verify that disabled network access really prevents a connection, or confirm that enabled access is limited as intended. Do not use real secrets as a test.
  9. Run the task and inspect the output. Keep the input copy separate from the original. Review commands, changes, and generated files before moving anything back to the host. Copy back only the files you need, and inspect them for unexpected scripts, configuration changes, or embedded secrets before opening or running them.
  10. Reset or remove the environment. When finished, revoke any temporary credentials, remove unneeded shared folders, and delete the disposable VM or container if you do not need it. A VM snapshot can help restore a clean state, but snapshots may retain secrets, so do not keep them longer than necessary.

Common Mistakes

Mounting the whole home directory: This defeats the goal by making personal files reachable. Share one dedicated project folder instead. Assuming a container is a VM: Containers share the host kernel, and unsafe mounts or elevated privileges weaken separation. Choose a VM for a stronger boundary when running untrusted code.

Leaving credentials in the project: An agent can read files available to it, regardless of whether a prompt says to protect them. Remove secrets before copying files. Enabling every convenience feature: Shared clipboard, folders, devices, and unrestricted networking expand what can cross the boundary. Enable only what the task needs.

Trusting a clean-looking result: Generated files may contain unexpected commands or altered configuration. Review outputs before using them on the host, especially before executing scripts.

Tips

  • Keep a clean base image and create a fresh disposable environment for risky or one-off tasks.
  • Use a separate, non-sensitive test account inside the guest if the agent needs to interact with an account.
  • Prefer read-only inputs and a dedicated output directory. This makes accidental overwrites easier to spot and undo.
  • Keep a short record of what was shared, which network access was enabled, and whether credentials were introduced.
  • Remember that isolation reduces exposure but cannot make a setup risk-free. Keep backups of important host files and avoid opening unreviewed output.

Troubleshooting

The agent cannot find the project: Check the guest’s workspace path and confirm that the intended folder was copied or mounted. Do not solve this by sharing the entire drive; correct the narrow path instead.

A required download or API call fails: Confirm whether network access is disabled, then allow only the connection needed. If credentials are required, use a limited temporary credential and remove it after the task. Do not switch on unrestricted access without considering what else the agent can reach.

Host files appear in the sandbox: Stop the agent, disconnect shared folders and devices, and inspect the VM or container configuration for broad mounts or elevated permissions. If sensitive files may have been accessible, assume they could have been read; revoke exposed credentials and replace the environment with a clean one.

The sandbox runs out of space or memory: Stop the task and increase the guest’s resource allocation only as needed. Keep limits in place, and remove disposable downloads or temporary files inside the guest rather than expanding access to host storage.

The agent changes files unexpectedly: Stop it, preserve the original project, and inspect the sandbox copy and logs. Restore from a clean copy or snapshot, then narrow the workspace and require confirmation for consequential actions if that option is available.

Frequently Asked Questions

Is a container enough to protect my main files?
A properly restricted container can separate a task’s files, but containers share the host kernel. Avoid privileged mode and broad host mounts; use a VM when you need a stronger boundary for untrusted code.

Can I let the agent use the internet?
Yes, if the task requires it, but allow only necessary access where possible. Network access can let software send data outward, so it is not a replacement for removing secrets from the workspace.

Should I give the agent my API key?
Avoid doing so unless essential. If required, use a narrowly scoped, temporary key, keep it out of project files and logs, and revoke it after the task.

Can I use my main project folder directly?
Make a separate copy first. This limits accidental edits and avoids exposing files that are present elsewhere in the original folder.

Does a snapshot make the sandbox safe?
A snapshot helps restore a prior state, but it does not prevent access to files, networks, or devices. It can also preserve credentials, so use it alongside isolation controls and remove sensitive snapshots when no longer needed.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →