https://github.com/zxbing0066/z-sandbox
A simple Sandbox implementation for Javascript
https://github.com/zxbing0066/z-sandbox
javascript sandbox
Last synced: about 1 year ago
JSON representation
A simple Sandbox implementation for Javascript
- Host: GitHub
- URL: https://github.com/zxbing0066/z-sandbox
- Owner: ZxBing0066
- License: mit
- Created: 2019-10-18T06:41:23.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-02-03T05:02:15.000Z (over 3 years ago)
- Last Synced: 2025-04-23T00:05:58.515Z (about 1 year ago)
- Topics: javascript, sandbox
- Language: JavaScript
- Size: 2.66 MB
- Stars: 33
- Watchers: 1
- Forks: 3
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# A simple Sandbox implementation for JavaScript
## Preview

## Demo
[](https://codesandbox.io/s/quirky-microservice-8oqog?fontsize=14)
## How to use
### Install from the npm
```bash
npm install z-sandbox
# or
yarn add z-sandbox
```
### Use in your code
```javascript
import { createSandbox } from 'z-sandbox';
const sandboxOptions = {
// default: false
useStrict: false,
// default: true
inheritGlobal: true,
// default: []
blacklist: ['blacklistContent']
};
const context = {
blacklistContent: "this content is in the blacklist, you can't get it in the sandbox",
hello: 'hello z-sandbox'
};
const sandbox = createSandbox(context, sandboxOptions);
sandbox`
// should be undefined
console.log(blacklistContent);
// should be undefined
console.log(window.blacklistContent);
// should be undefined
console.log(this.blacklistContent);
// should be undefined
console.log(self.blacklistContent);
// should be 'hello z-sandbox'
console.log(hello);
window.testInject = true;
// should be true
console.log(window.testInject);
`;
// should be undefined, false
console.log(window.testInject, 'testInject' in window);
```