{"id":23577082,"url":"https://github.com/codesandbox/codesandbox-sdk","last_synced_at":"2025-04-05T15:02:41.461Z","repository":{"id":267905788,"uuid":"902399072","full_name":"codesandbox/codesandbox-sdk","owner":"codesandbox","description":"Programmatically start (AI) sandboxes on top of CodeSandbox","archived":false,"fork":false,"pushed_at":"2025-03-13T15:22:35.000Z","size":435,"stargazers_count":60,"open_issues_count":13,"forks_count":8,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-03-28T05:38:20.802Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://codesandbox.io/docs/sdk","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/codesandbox.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2024-12-12T13:45:49.000Z","updated_at":"2025-03-26T00:25:43.000Z","dependencies_parsed_at":"2024-12-13T06:35:42.447Z","dependency_job_id":"780e0f3e-84e7-40e8-8c24-3f76161cf12e","html_url":"https://github.com/codesandbox/codesandbox-sdk","commit_stats":{"total_commits":9,"total_committers":1,"mean_commits":9.0,"dds":0.0,"last_synced_commit":"393d53c68bc4ea33983302fc2056727126124fc8"},"previous_names":["codesandbox/codesandbox-sdk"],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codesandbox%2Fcodesandbox-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codesandbox%2Fcodesandbox-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codesandbox%2Fcodesandbox-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codesandbox%2Fcodesandbox-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codesandbox","download_url":"https://codeload.github.com/codesandbox/codesandbox-sdk/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247353729,"owners_count":20925329,"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-12-26T22:19:25.280Z","updated_at":"2025-04-05T15:02:41.434Z","avatar_url":"https://github.com/codesandbox.png","language":"TypeScript","funding_links":[],"categories":["TypeScript","Evaluation, Observability \u0026 Sandboxing","[Together Code Sandbox](https://www.together.ai/code-sandbox)"],"sub_categories":["Tier 3: Complex Projects (Platforms \u0026 Orchestration)"],"readme":"# CodeSandbox SDK\n\n\u003e The power of CodeSandbox in a library\n\nCodeSandbox SDK enables you to programmatically spin up development environments and run untrusted code. It provides a programmatic API to create and run sandboxes quickly and securely.\n\nUnder the hood, the SDK uses the microVM infrastructure of CodeSandbox to spin up sandboxes. It supports:\n\n- Snapshotting/restoring VMs (checkpointing) at any point in time\n  - With snapshot restore times within 1 second\n- Cloning VMs \u0026 Snapshots within 2 seconds\n- Source control (git, GitHub, CodeSandbox SCM)\n- Running any Dockerfile\n\nCheck out the [CodeSandbox SDK documentation](https://codesandbox.io/docs/sdk) for more information.\n\n## Getting Started\n\nTo get started, install the SDK:\n\n```bash\nnpm install @codesandbox/sdk\n```\n\nCreate an API token by going to https://codesandbox.io/t/api, and clicking on the \"Create API Token\" button. You can then use this token to authenticate with the SDK:\n\n```javascript\nimport { CodeSandbox } from \"@codesandbox/sdk\";\n\n// Create the client with your token\nconst sdk = new CodeSandbox(token);\n\n// This creates a new sandbox by forking our default template sandbox.\n// You can also pass in other template ids, or create your own template to fork from.\nconst sandbox = await sdk.sandbox.create();\n\n// You can run JS code directly\nawait sandbox.shells.js.run(\"console.log(1+1)\");\n// Or Python code (if it's installed in the template)\nawait sandbox.shells.python.run(\"print(1+1)\");\n\n// Or anything else\nawait sandbox.shells.run(\"echo 'Hello, world!'\");\n\n// We have a FS API to interact with the filesystem\nawait sandbox.fs.writeTextFile(\"./hello.txt\", \"world\");\n\n// And you can clone sandboxes! This does not only clone the filesystem, processes that are running in the original sandbox will also be cloned!\nconst sandbox2 = await sandbox.fork();\n\n// Check that the file is still there\nawait sandbox2.fs.readTextFile(\"./hello.txt\");\n\n// You can also get the opened ports, with the URL to access those\nconsole.log(sandbox2.ports.getOpenedPorts());\n\n// Getting metrics...\nconst metrics = await sandbox2.getMetrics();\nconsole.log(\n  `Memory: ${metrics.memory.usedKiB} KiB / ${metrics.memory.totalKiB} KiB`\n);\nconsole.log(`CPU: ${(metrics.cpu.used / metrics.cpu.cores) * 100}%`);\n\n// Finally, you can hibernate a sandbox. This will snapshot the sandbox and stop it. Next time you start the sandbox, it will continue where it left off, as we created a memory snapshot.\nawait sandbox.hibernate();\nawait sandbox2.hibernate();\n\n// Open the sandbox again\nconst resumedSandbox = await sdk.sandbox.open(sandbox.id);\n```\n\n## CodeSandbox Integration\n\nThis SDK uses the API token from your workspace in CodeSandbox to authenticate and create sandboxes. Because of this, the sandboxes will be created inside your workspace, and the resources will be billed to your workspace.\n\nYou could, for example, create a private template in your workspace that has all the dependencies you need (even running servers), and then use that template to fork sandboxes from. This way, you can control the environment that the sandboxes run in.\n\n## Example Use Cases\n\nThese are some example use cases that you could use this library for:\n\nCode interpretation: Run code in a sandbox to interpret it. This way, you can run untrusted code without worrying about it affecting your system.\n\nDevelopment environments: Create a sandbox for each developer, and run their code in the sandbox. This way, you can run multiple development environments in parallel without them interfering with each other.\n\nAI Agents: Create a sandbox for each AI agent, and run the agent in the sandbox. This way, you can run multiple agents in parallel without them interfering with each other. Using the forking mechanism, you can also A/B test different agents.\n\nCI/CD: Run tests inside a sandbox, and hibernate the sandbox when the tests are done. This way, you can quickly start the sandbox again when you need to run the tests again or evaluate the results.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodesandbox%2Fcodesandbox-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodesandbox%2Fcodesandbox-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodesandbox%2Fcodesandbox-sdk/lists"}