{"id":15169965,"url":"https://github.com/golemfactory/v8-wasm","last_synced_at":"2025-10-01T04:30:32.201Z","repository":{"id":86423645,"uuid":"162142753","full_name":"golemfactory/v8-wasm","owner":"golemfactory","description":"v8-based Wasm sandbox","archived":true,"fork":false,"pushed_at":"2019-03-19T11:36:54.000Z","size":66892,"stargazers_count":7,"open_issues_count":0,"forks_count":6,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-09-18T22:59:57.938Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/golemfactory.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-12-17T14:27:32.000Z","updated_at":"2023-03-29T01:45:14.000Z","dependencies_parsed_at":"2023-11-28T02:15:09.255Z","dependency_job_id":null,"html_url":"https://github.com/golemfactory/v8-wasm","commit_stats":{"total_commits":7,"total_committers":2,"mean_commits":3.5,"dds":0.2857142857142857,"last_synced_commit":"534e5f6977de091d7d27df9590808003a54e419a"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/golemfactory%2Fv8-wasm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/golemfactory%2Fv8-wasm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/golemfactory%2Fv8-wasm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/golemfactory%2Fv8-wasm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/golemfactory","download_url":"https://codeload.github.com/golemfactory/v8-wasm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219866483,"owners_count":16554237,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-09-27T07:42:04.249Z","updated_at":"2025-10-01T04:30:26.855Z","avatar_url":"https://github.com/golemfactory.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# v8-based WebAssembly Sandbox\n\n## Overview\n\nThis is a proof of concept for a JavaScript + WebAssembly standalone sandbox implemented in `C++` utilizing the `V8` engine.\n\n## Building\n\n1. First of all, you have to build the V8 monolith library (`libv8_monolith.a`).\nInstructions can be found [here](https://v8.dev/docs/embed#hello-world)\n2. A compiler supporting C++17 along with the `filesystem` library has to be used for building, e.g. `g++-8`.\n3. Inside the project root:\n```\nmkdir build\ncd build\ncmake .. \\\n    -DCMAKE_CXX_COMPILER={path to an appropriate compiler (see 2. above)} \\\n    -DV8_INCLUDE_DIR={path to the v8 include/ dir} \\\n    -DV8_MONOLITH_LIB_PATH={path to the compiled libv8_monolith.a from 1. above}\nmake\n```\n4. The above should leave you with a working `wasm-sandbox` executable.\n\n## Running\n\nExample:\n```bash\n./wasm-sandbox -O output/ -I input/ -j program.js -w program.wasm\\\n    -o output_file1 -o output_file2 -- program_arg1 --program_flag1 program_arg2\n```\n\n### Flags:\n\n* `-O` : Path to the output directory. All files specified by `-o` will be copied from the program\n virtual filesystem to this directory.\n* `-I` : Path to the input directory. The contents of this directory will be mapped as `/` in the\nprogram's virtual filesystem (which is also the *CWD* of the program).\n* `-w` : Path to the WebAssembly program file produced by the compiler (e.g. Emscripten).\n* `-j` : Path to the JavaScript program file produced by the compiler (e.g. Emscripten).\n* `-o` [**repeated**] : Path to an output file produced by the program inside its virtual filesystem.\nEach file specified by this flag will be copied to the directory specified by `-O` after the program\nfinishes. If any of the files specified by `-o` cannot be found after the program finishes, an exception\nwill be raised.\n* `--` : Anything after this will be passed to the program being run as arguments.\n\n### Program restrictions\n\nCurrently only programs compiled by *Emscripten* are supported. Furthermore, the following flags\n**have** to be used while compiling via *emcc*:\n\n* `-s BINARYEN_ASYNC_COMPILATION=0` - without this, the program will not actually run, but it\nwon't show any errors (quite difficult to debug). This is due to the fact that the sandbox\ndoesn't implement any sort of asynchronicity on top of V8, so the WebAssembly compilation has\nto be done synchronously.\n* `-s MEMFS_APPEND_TO_TYPED_ARRAYS=1` - without this, writing bigger (the actual size seems\nto depend on the program) files will fail with OOM errors.\n\nIf the program uses any substantial amount of memory, the following flags may also be useful:\n\n* `-s ALLOW_MEMORY_GROWTH=1` \n* `-s TOTAL_MEMORY=1073741824` (or another number, though there are restrictions). It seems to\nsometimes be required to specify this flag even though `-s ALLOW_MEMORY_GROWTH=1` is specified\nas well (see the [flite](examples/flite) example).\n\n### Example:\n\nLet's say `test.c` takes a string argument, reads `in.txt` file and writes the following\nstring: `Hello world!\\n{contents of the input file}\\n{the argument}\\n` to `out.txt` file.\n\nFirst, we compile the program using *Emscripten*:\n\n```bash\nemcc test.c -o test.js -s BINARYEN_ASYNC_COMPILATION=0 -s MEMFS_APPEND_TO_TYPED_ARRAYS=1 -s ALLOW_MEMORY_GROWTH=1\n```\n\nThis produces 2 files, `test.js` and `test.wasm`. Then, we create directories for the program's\ninput and output:\n\n```bash\nmkdir input output\necho \"interesting file contents\" \u003e input/in.txt\n```\n\nFinally, we can run the program inside the sandbox:\n\n```bash\n./wasm-sandbox -I input -O output -j test.js -w test.wasm -o out.txt -- interesting_program_arg\n```\n\nAnd the we can read the results:\n\n```bash\ncat output/out.txt\n\u003e Hello world!\n\u003e interesting file contents\n\u003e interesting_program_arg\n```\n\nThe actual program can be found in [examples/test](examples/test), both as source and compiled into JS+WASM.\n\n## Wasm store\n\nMore examples of precompiled Wasm binaries can be found in [golemfactory/wasm-store](https://github.com/golemfactory/wasm-store) repo.\n\n## Possible TODOs\n\n* Allow outputing variable number of files (perhaps whole directories?).\n* Sync to a newer release of V8.\n* Figure out if there is a more performant way of linking V8 than `libv8_monolith.a`.\n* Create an abstract *Integrator* interface, which *EmscriptenIntegrator* will implement, if any\ndifferent integrators are needed in the future, targeting different compilers than *Emscripten*.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgolemfactory%2Fv8-wasm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgolemfactory%2Fv8-wasm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgolemfactory%2Fv8-wasm/lists"}