沙盒代码隔离

沙盒的一个小 demo,还挺实用的。主要是帮你在一个隔离的环境里跑代码,安全性高,出问题也不怕。像测试一些不太确定的功能、运行第三方库,或者搞搞前端的代码练习,都挺合适。尤其对做 iOS、Node.js 或者前端的小伙伴来说,这种东西不陌生。

沙盒的最大优势,是它能把运行环境隔离出来。你写的代码在里面跑,哪怕有 bug、甚至带点“毒”,也不会对主系统有啥影响。比如在 iOS 上,每个 App 的沙盒就相当于它的小地盘,别的 App 根本进不去。

前端这边,如果你喜欢用 ReactTypescript,可以用沙盒来搭建一些实验页面。配合像 iframepostMessage 这些特性,用来搞组件隔离、预览效果,还挺香。试试在 code sandbox 上搭个 demo,响应也快,代码也好分享。

做 Node.js 的朋友,也可以看看 Metavm,是个基于沙盒的脚本加载器。它能帮你把不太靠谱的代码圈起来跑,配合权限管理,出问题了也不会牵连主服务。

我这边压了个 sandbox 压缩包,里面有点基础源码、配置和 demo,感兴趣的可以扒拉着看看,自己撸一套也不难。如果你还在研究如何获取 沙盒路径缓存数据,下面这些文章也挺有参考价值:

嗯,如果你平时有测试环境需求、经常折腾代码或要预防意外操作,不妨搞一个沙盒系统,省心多了。

zip
sandbox.zip 预估大小:20个文件
folder
sandbox 文件夹
folder
sandbox.xcodeproj 文件夹
folder
project.xcworkspace 文件夹
file
contents.xcworkspacedata 152B
folder
xcuserdata 文件夹
folder
longyan.xcuserdatad 文件夹
file
UserInterfaceState.xcuserstate 17KB
file
project.pbxproj 14KB
folder
xcuserdata 文件夹
folder
longyan.xcuserdatad 文件夹
folder
xcschemes 文件夹
file
sandbox.xcscheme 3KB
file
xcschememanagement.plist 479B
folder
sandbox 文件夹
file
ViewController2.xib 388KB
file
sandbox-Prefix.pch 317B
file
AppDelegate.h 360B
file
sandbox-Info.plist 1KB
file
ViewController2.m 2KB
file
ViewController.h 432B
folder
en.lproj 文件夹
file
InfoPlist.strings 45B
file
ViewController.xib 390KB
file
Default-568h@2x.png 18KB
file
ViewController2.h 425B
file
main.m 332B
file
Default@2x.png 16KB
file
Default.png 6KB
file
AppDelegate.m 2KB
file
ViewController.m 1KB
zip 文件大小:212.32KB