{"id":15650862,"url":"https://github.com/healeycodes/deno-script-sandbox","last_synced_at":"2025-07-21T10:32:05.609Z","repository":{"id":112377980,"uuid":"599640465","full_name":"healeycodes/deno-script-sandbox","owner":"healeycodes","description":"🏜️ A sandbox that runs user-supplied JavaScript/TypeScript scripts.","archived":false,"fork":false,"pushed_at":"2023-06-17T18:25:26.000Z","size":12,"stargazers_count":51,"open_issues_count":1,"forks_count":8,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-30T17:39:18.267Z","etag":null,"topics":["sandbox","untrusted-code"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/healeycodes.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2023-02-09T15:15:39.000Z","updated_at":"2025-03-20T11:10:54.000Z","dependencies_parsed_at":"2024-10-03T12:37:51.553Z","dependency_job_id":"c6cc8bf1-82d7-485a-9414-6efd4f873329","html_url":"https://github.com/healeycodes/deno-script-sandbox","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/healeycodes/deno-script-sandbox","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/healeycodes%2Fdeno-script-sandbox","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/healeycodes%2Fdeno-script-sandbox/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/healeycodes%2Fdeno-script-sandbox/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/healeycodes%2Fdeno-script-sandbox/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/healeycodes","download_url":"https://codeload.github.com/healeycodes/deno-script-sandbox/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/healeycodes%2Fdeno-script-sandbox/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266285377,"owners_count":23905331,"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":["sandbox","untrusted-code"],"created_at":"2024-10-03T12:36:06.943Z","updated_at":"2025-07-21T10:32:05.589Z","avatar_url":"https://github.com/healeycodes.png","language":"TypeScript","readme":"# deno-script-sandbox\n\n\u003e My blog post: [Sandboxing JavaScript Code](https://healeycodes.com/sandboxing-javascript-code)\n\n\u003cbr\u003e\n\nI wanted to sandbox some JavaScript/TypeScript code and this is the best idea I could come up with given a few hours coding time.\n\nI'm not a security engineer so run this at your absolute peril.\n\nThe API allows untrusted execution of a user-supplied code and returns stdout/stderr – but enforces limits on execution time, memory usage, and access to the internet and disk. This is powered by Deno's [Permissions](https://deno.land/manual@v1.26.0/getting_started/permissions) settings.\n\nThe API starts a `sandbox.ts` script with locked down permissions that dynamically imports user-supplied code – which means users can send stuff like `console.log(1 + 1)` and then see the result. `fetch` is patched so that it hits the proxy and sends the original URL in the headers.\n\nScripts can only access URLs from `safeURLs` in `utils.ts`. There are also limits on the number of requests per script run.\n\nThere's a concurrency limit on the number of scripts being executed at once but there's no protections against things like DDOS.\n\nUsers can run stuff like:\n\n```ts\nconsole.log('hi world!');\n```\n\nor\n\n```ts\nconst res = await fetch(\"https://hacker-news.firebaseio.com/v0/item/8863.json?print=pretty\");\nconsole.log(res.status, await res.text());\n```\n\nErrors can be surfaced to users by reading the stderr in the API's response:\n\n```ts\na;\n/*\n{ \"status\": { \"success\": true, \"code\": 0 },\n  \"stdout\": \"\",\n  \"stderr\": \"ReferenceError: a is not defined\\n    at 3ab3252c-0ea7-4058-9cf9-1b0c0b3001c8.ts:1:1\\n\"\n}\n*/\n```\n\nUsers can't run stuff like:\n\n```ts\n// This hits a heap limit error due to `--v8-flags=--max-old-space-size` (importantly, the API doesn't crash)\nconst a = [];\nfor (let i = 0; i \u003c 9000000000; i++) {\n    a.push(i)\n}\n```\n\nor\n\n```ts\n// This hits an access error due to Deno permissions\nawait Deno.writeTextFile(\"./hello.txt\", \"Hello World!\");\n```\n\nor\n\n```ts\n// This won't error but the proxy returns (400, \"only these URLs are allowed ...\")\nconst res = await fetch(\"https://some-non-safe-url.com\");\nconsole.log(res.status, await res.text())\n```\n\n## Run\n\n`deno run -A api.ts`\n\nSend a test script with `deno run -A local-dev.ts`\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhealeycodes%2Fdeno-script-sandbox","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhealeycodes%2Fdeno-script-sandbox","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhealeycodes%2Fdeno-script-sandbox/lists"}