# Sandbox (computer security)

In computer security, a sandbox is a security mechanism for separating running programs, usually in an effort to mitigate system failures and/or software vulnerabilities from spreading. The sandbox metaphor derives from the concept of a child's sandbox—a play area where children can build, destroy, and experiment without causing any real-world damage. It is often used to kill untested or untrusted programs or code, possibly from unverified or untrusted third parties, suppliers, users or websites, without risking harm to the host machine or operating system. A sandbox typically provides a tightly controlled set of resources for guest programs to run in, such as storage and memory scratch space. Network access, the ability to inspect the host system, or read from input devices are usually disallowed or heavily restricted.
In the sense of providing a highly controlled environment, sandboxes may be seen as a specific example of virtualization. Sandboxing is frequently used to test unverified programs that may contain a virus or other malicious code without allowing the software to harm the host device.

## Implementations

A sandbox is implemented by executing the software in a restricted operating system environment, thus controlling the resources (e.g. file descriptors, memory, file system space, etc.) that a process may use.
Examples of sandbox implementations include the following:
* Linux application sandboxing, built on Seccomp, cgroups and Linux namespaces. Notably used by Systemd, Google Chrome, Firefox, Firejail.
* Android was the first mainstream operating system to implement full application sandboxing, built by assigning each application its own Linux user ID.
* Apple App Sandbox is required for apps distributed through Apple's Mac App Store and iOS/iPadOS App Store, and recommended for other signed apps.
* Windows Vista and later editions include a "low" mode process running, known as "User Account Control" (UAC), which only allows writing in a specific directory and registry keys. Windows 10 Pro, from version 1903, provides a feature known as Windows Sandbox.
* Google Sandboxed API.
* Virtual machines emulate a complete host computer, on which a conventional operating system may boot and run as on actual hardware. The guest operating system runs sandboxed in the sense that it does not function natively on the host and can only access host resources through the emulator.
* A jail: network-access restrictions, and a restricted file system namespace. Jails are most commonly used in virtual hosting.
* Rule-based execution gives users full control over what processes are started, spawned (by other applications), or allowed to inject code into other applications and have access to the net, by having the system assign access levels for users or programs according to a set of determined rules. It also can control file/registry security (what programs can read and write to the file system/registry). In such an environment, viruses and Trojans have fewer opportunities for infecting a computer. The SELinux and Apparmor security frameworks are two such implementations for Linux.
* Security researchers rely heavily on sandboxing technologies to analyse malware behavior. By creating an environment that mimics or replicates the targeted desktops, researchers can evaluate how malware infects and compromises a target host. Numerous malware analysis services are based on the sandboxing technology.
* Google Native Client is a sandbox for running compiled C and C++ code in the browser efficiently and securely, independent of the user's operating system.
* Capability systems can be thought of as a fine-grained sandboxing mechanism, in which programs are given opaque tokens when spawned and have the ability to do specific things based on what tokens they hold. Capability-based implementations can work at various levels, from kernel to user-space. An example of capability-based user-level sandboxing involves HTML rendering in a Web browser.
* Secure Computing Mode (seccomp) strict mode, seccomp only allows the write, read, exit, and sigreturn system calls.
* HTML5 has a "sandbox" attribute for use with iframes.
* Java virtual machines include a sandbox to restrict the actions of untrusted code, such as a Java applet.
* The .NET Common Language Runtime provides Code Access Security to enforce restrictions on untrusted code.
* Software Fault Isolation (SFI), allows running untrusted native code by sandboxing all store, read and jump assembly instructions to isolated segments of memory.
Some of the use cases for sandboxes include the following:
* Online judge systems to test programs in programming contests.
* New-generation pastebins allowing users to execute pasted code snippets on the pastebin's server.