Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
273 commits
Select commit Hold shift + click to select a range
0e5f742
chore(main): release 0.3.0 (#34)
CompuIves Jan 14, 2025
491d13d
feat: support for creating sessions (#32)
CompuIves Jan 22, 2025
4b27757
chore(main): release 0.4.0 (#35)
CompuIves Jan 22, 2025
1e9e19c
feat: list sandboxes by running status (#37)
CompuIves Jan 28, 2025
f086bb8
feat: add more advanced pagination options (#39)
CompuIves Jan 28, 2025
116c513
tweak: list api (#40)
CompuIves Jan 28, 2025
85d77a9
tweak: rename header (#41)
CompuIves Jan 28, 2025
7f4b063
tweak: use console error for limit log (#42)
CompuIves Jan 28, 2025
60cf5bb
chore(main): release 0.5.0 (#38)
CompuIves Jan 28, 2025
67c8a2c
update pitcher-client to fix pong detection issue
christianalfoni Jan 30, 2025
2e63156
Merge pull request #43 from codesandbox/update-pitcher-client
christianalfoni Jan 30, 2025
c8e6f46
fix: uploads of big files (#44)
christianalfoni Jan 30, 2025
8c56c58
chore(main): release 0.5.1 (#45)
CompuIves Jan 30, 2025
4691813
fix: esm node build (#36)
CompuIves Jan 30, 2025
eee9117
chore(main): release 0.5.2 (#46)
CompuIves Jan 30, 2025
7fc76a5
fix: use cjs for binary (#47)
CompuIves Jan 30, 2025
92ea845
chore(main): release 0.5.3 (#48)
CompuIves Jan 30, 2025
64abff8
fix(snapshot): don't include ignorefiles when building snapshots (#50)
CompuIves Feb 6, 2025
7bf1e35
feat: support env and cwd in shell api (#52)
CompuIves Feb 6, 2025
7ad63d7
feat: allow sandbox to keep active while connected (#53)
CompuIves Feb 6, 2025
b7d19ae
chore(main): release 0.6.0 (#51)
CompuIves Feb 6, 2025
d8e4c6f
perf: do hibernation and shutdown in parallel (#54)
CompuIves Feb 8, 2025
23d1469
chore(main): release 0.6.1 (#55)
CompuIves Feb 8, 2025
528022e
fix: CommonJS build requires .cjs extension for ESM package (#56)
wylieconlon Feb 10, 2025
be0138a
chore(deps-dev): bump esbuild from 0.24.0 to 0.25.0 (#58)
dependabot[bot] Feb 10, 2025
20a2d48
chore(main): release 0.6.2 (#57)
CompuIves Feb 10, 2025
00e8c20
feat: add support for passing name and path to cli (#60)
CompuIves Feb 15, 2025
eed86b1
chore(main): release 0.7.0 (#61)
CompuIves Feb 15, 2025
993e509
feat: support for private previews and preview tokens (#63)
CompuIves Feb 18, 2025
5a5d659
chore(main): release 0.8.0 (#64)
CompuIves Feb 18, 2025
7b61dcc
fix: don't use env if not env vars are set (#66)
CompuIves Feb 21, 2025
83cc549
chore(main): release 0.8.1 (#67)
CompuIves Feb 21, 2025
f054205
feat: add support for `--since` when listing sandboxes (#68)
CompuIves Feb 26, 2025
24ab04f
chore(main): release 0.9.0 (#69)
CompuIves Feb 26, 2025
27c559c
feat: allow defining timeout when waiting for port (#70)
CompuIves Feb 28, 2025
25035bb
chore(main): release 0.10.0 (#71)
CompuIves Feb 28, 2025
c9a3aea
working rest client
christianalfoni Mar 6, 2025
bc90eab
clean up
christianalfoni Mar 6, 2025
318a66c
chore: fix wrong example in docs (#78)
CompuIves Mar 10, 2025
8c2ef89
feat: add support for configuring auto-wake behaviour (#79)
CompuIves Mar 11, 2025
6aa5387
chore(main): release 0.11.0 (#80)
CompuIves Mar 11, 2025
ca1f825
fix: support `keepActiveWhileConnected` for browser sessions (#81)
CompuIves Mar 13, 2025
cb67ca6
chore(main): release 0.11.1 (#82)
CompuIves Mar 13, 2025
157691a
tend to feedback and add full fs spec
christianalfoni Apr 2, 2025
daad8c7
it is running
christianalfoni Apr 7, 2025
a7a1b74
merge
christianalfoni Apr 8, 2025
c5a2469
fix(build): consider port opened for faulty status codes (#84)
CompuIves Apr 15, 2025
0030774
chore(main): release 0.11.2 (#85)
CompuIves Apr 15, 2025
ec8f5eb
Merge pull request #73 from codesandbox/protocol-openapi
christianalfoni Apr 22, 2025
92ec419
add property to check if VM is up to date
christianalfoni Apr 24, 2025
5468182
Update src/sandbox.ts
christianalfoni Apr 24, 2025
a44c842
Merge pull request #89 from codesandbox/expose-is-up-to-date
christianalfoni Apr 24, 2025
d7a2902
chore(main): release 0.12.0
CompuIves Apr 24, 2025
eda1e8e
Merge pull request #88 from codesandbox/release-please--branches--mai…
christianalfoni Apr 24, 2025
6b6b0ad
WIP
christianalfoni Apr 28, 2025
80875ba
working state
christianalfoni Apr 28, 2025
c206765
more cleanup
christianalfoni Apr 29, 2025
51f46bf
add git sandbox
christianalfoni Apr 29, 2025
df49617
fix browser sessions
christianalfoni Apr 29, 2025
58985d1
fixed ports and other stuff
christianalfoni Apr 30, 2025
d356a4b
fix tasks
christianalfoni Apr 30, 2025
c1f96c1
reworked api
christianalfoni Apr 30, 2025
dea66d2
okay, sessions
christianalfoni Apr 30, 2025
286a73a
move preview tokens
christianalfoni Apr 30, 2025
5a02b28
fix disposal of shell
christianalfoni May 2, 2025
01b6568
updated todo
christianalfoni May 2, 2025
6e2705f
export all types and test task listener
christianalfoni May 2, 2025
1389d01
improve shells
christianalfoni May 5, 2025
f12327a
previews
christianalfoni May 6, 2025
d147321
rename
christianalfoni May 6, 2025
81ee0f3
expose terminals, commands and interpreters
christianalfoni May 7, 2025
42fcc15
wrap up interpreters and prevent process error on first try
christianalfoni May 8, 2025
e8933a9
working
christianalfoni May 9, 2025
b46ca5b
awesome tasks
christianalfoni May 9, 2025
f3f9c60
some changes
christianalfoni May 9, 2025
c471b06
Ready for beta... I think
christianalfoni May 12, 2025
c446d01
ready...
christianalfoni May 12, 2025
bfb5a12
new setup approach
christianalfoni May 12, 2025
26671e6
preview hosts and command fix
christianalfoni May 13, 2025
58558da
fix run commands
christianalfoni May 14, 2025
211a07d
things
christianalfoni May 14, 2025
9d2e766
Wop
christianalfoni May 14, 2025
43780a7
expose preview
christianalfoni May 14, 2025
89f57ac
fix naming of stuff
christianalfoni May 15, 2025
f472813
fix python inteprreter and template CLI visuals
christianalfoni May 15, 2025
43d378d
documenting
christianalfoni May 19, 2025
edfad0b
fix preview tokens
christianalfoni May 19, 2025
cef0ce0
several updates
christianalfoni May 20, 2025
ffc629d
latest fixes
christianalfoni May 20, 2025
74fe27f
fix terminals and commands list
christianalfoni May 20, 2025
068504d
fix cli
christianalfoni May 20, 2025
a14aa23
Use micro for template building
christianalfoni May 20, 2025
bc0ac58
default to micro for create and start
christianalfoni May 20, 2025
c655a66
ready for release
christianalfoni May 20, 2025
94caf9e
blah
christianalfoni May 20, 2025
069b7c5
fixed
christianalfoni May 20, 2025
8127b49
Merge pull request #94 from codesandbox/new-release
christianalfoni May 20, 2025
02b1b16
several fixes
christianalfoni May 21, 2025
a53293a
bump version
christianalfoni May 21, 2025
07c6963
export hosts types
christianalfoni May 21, 2025
c7ac36f
actually export it
christianalfoni May 21, 2025
73cc0a3
unlisted by default
christianalfoni May 21, 2025
49ecec8
actually pass the host token on browser sessions
christianalfoni May 21, 2025
c60b62e
Merge pull request #96 from codesandbox/updates
christianalfoni May 21, 2025
fdd335d
super duper
christianalfoni May 22, 2025
d60257b
fix typo and paths with dedicated sessions
christianalfoni May 22, 2025
437a31d
Use join result username
christianalfoni May 22, 2025
da5e3f6
Merge pull request #99 from codesandbox/new-version-fixes
christianalfoni May 22, 2025
2636d47
Fix session create bug when passing in git credentials
ymichael May 22, 2025
2284e39
fix restart of clusters
christianalfoni May 23, 2025
da518c9
fix failing commands
christianalfoni May 23, 2025
0496965
Merge pull request #101 from ymichael/ymichael/fix-session-creation
christianalfoni May 24, 2025
dd624bd
POC
christianalfoni May 26, 2025
c9cfbf9
moving on
christianalfoni May 26, 2025
c478800
fix them
christianalfoni May 26, 2025
e334e4e
merge
christianalfoni May 26, 2025
443f5a2
allow running commands as global session
christianalfoni May 26, 2025
3ad4f10
Merge pull request #104 from codesandbox/new-release-fixes
christianalfoni May 26, 2025
a8cb000
Merge branch 'main' into fix-wrong-names
christianalfoni May 26, 2025
474261f
Merge pull request #106 from codesandbox/fix-wrong-names
christianalfoni May 26, 2025
0167af0
call `onStatusChangeEmitter` on `status` change
zhelezkov May 27, 2025
af8fad9
decoupled and tested
christianalfoni May 27, 2025
fd37ece
merge
christianalfoni May 27, 2025
765ca90
Merge pull request #109 from zhelezkov/fix/command-on-status-change
christianalfoni May 27, 2025
82bcf74
use ws and drop banner
christianalfoni May 28, 2025
475d499
remove together-common and update default template id
christianalfoni Jun 2, 2025
d544e9d
fix scheduling hack
christianalfoni Jun 2, 2025
7914209
cluster fix
christianalfoni Jun 2, 2025
3765562
fix building of templates
christianalfoni Jun 2, 2025
e7bb559
fix templates
christianalfoni Jun 2, 2025
10b0b1d
Merge pull request #111 from codesandbox/quick-fix
christianalfoni Jun 2, 2025
4607933
merge
christianalfoni Jun 2, 2025
40123be
add aliases
christianalfoni Jun 3, 2025
e535878
update openapi
christianalfoni Jun 3, 2025
a4bca66
merge
christianalfoni Jun 3, 2025
75d1512
first version
christianalfoni Jun 3, 2025
8b5a4f0
recover building templates
christianalfoni Jun 4, 2025
d22794f
fix polling of running state
christianalfoni Jun 5, 2025
cf00054
introduce ci flag for template building
christianalfoni Jun 5, 2025
b692478
fix retry
christianalfoni Jun 5, 2025
a15cf6d
version bump
christianalfoni Jun 5, 2025
04ee301
new template
christianalfoni Jun 5, 2025
5598377
ports fallback
christianalfoni Jun 6, 2025
a0f76f9
fix timeout
christianalfoni Jun 6, 2025
9fd3edc
git running
christianalfoni Jun 6, 2025
c04ffdf
fix
christianalfoni Jun 6, 2025
6f34b3c
env fix
christianalfoni Jun 6, 2025
81f63e7
new node client
christianalfoni Jun 13, 2025
0d63915
deprecate fork
christianalfoni Jun 13, 2025
85eb580
add createBranch
christianalfoni Jun 16, 2025
a25abc4
sentry and new templates endpoint
christianalfoni Jun 17, 2025
e17e0ec
bring back cluster info to CLI
christianalfoni Jun 17, 2025
e0cbf32
force expiry on host tokens and improved template builder
christianalfoni Jun 19, 2025
dd3c46a
remove test step
christianalfoni Jun 19, 2025
5028bb0
strip ansi codes
christianalfoni Jun 25, 2025
f551ced
initialize session also on createSession
christianalfoni Jun 25, 2025
d93e37d
remove sentry from SDK, only use in CLI
christianalfoni Jun 25, 2025
c1d3f68
finally git and env working
christianalfoni Jun 26, 2025
3637c84
clean podman command errors
christianalfoni Jun 26, 2025
ff9ffa8
remove git
christianalfoni Jun 26, 2025
44bb498
remove import
christianalfoni Jun 27, 2025
99d38d5
more fixes
christianalfoni Jun 30, 2025
233999e
properly exit as error when failing Sandbox creation
christianalfoni Jun 30, 2025
790f08c
fix error in ci
christianalfoni Jun 30, 2025
37f2ab5
Merge pull request #113 from codesandbox/decoupling
christianalfoni Jun 30, 2025
15965d1
fix keepAliveWhileConnected logic
wylieconlon Jun 30, 2025
890c6c1
fix typo
wylieconlon Jun 30, 2025
ba61554
Make readme reflect current state of lib
christianalfoni Jul 1, 2025
6294684
Merge pull request #119 from wylieconlon/wylie/6-30-25_fix-keepAlive
christianalfoni Jul 1, 2025
f9fe27a
Merge branch 'main' into new-version-fixes-2
christianalfoni Jul 1, 2025
2cbc69e
fix keep active while connected
christianalfoni Jul 1, 2025
29cad67
Better output for template creation, also creating Sandbox to verify
christianalfoni Jul 1, 2025
a5a9bb1
adjust lines
christianalfoni Jul 1, 2025
76af091
Merge pull request #120 from codesandbox/new-version-fixes-2
christianalfoni Jul 1, 2025
78efcfb
Update package-lock after installing
tristandubbeld Jul 2, 2025
75f56da
fix: add apiClient to context and pass to query fn
tristandubbeld Jul 2, 2025
0119379
Merge pull request #122 from codesandbox/fix/add-api-client-to-runnin…
christianalfoni Jul 2, 2025
6d455ad
fix: Template resolve files fixes (#121)
christianalfoni Jul 2, 2025
82ec4c3
chore(main): release 2.0.2 (#123)
CompuIves Jul 2, 2025
09d9e8a
fix: disable sentry by default, make it optional (#126)
CompuIves Jul 8, 2025
e6f2caf
chore(main): release 2.0.3
CompuIves Jul 8, 2025
988b892
Merge pull request #127 from codesandbox/release-please--branches--ma…
tristandubbeld Jul 9, 2025
0211660
fix: fix dependencies
mojojoji Jul 15, 2025
77f74f1
Merge pull request #128 from codesandbox/fix/devdependency-to-dependency
mojojoji Jul 16, 2025
a5e3e89
chore(main): release 2.0.4
CompuIves Jul 16, 2025
5ab4da7
Merge pull request #130 from codesandbox/release-please--branches--ma…
mojojoji Jul 16, 2025
fd7364d
Fix timeout errors on keepActiveWhileConnected
christianalfoni Jul 28, 2025
a519bcf
Merge pull request #135 from codesandbox/christianalfoni-patch-1
tristandubbeld Jul 29, 2025
0beb619
chore(main): release 2.0.5
CompuIves Jul 29, 2025
281a2bd
Merge pull request #136 from codesandbox/release-please--branches--ma…
tristandubbeld Jul 29, 2025
be1735f
Fix field name in SandboxSession type (#133)
fertapric-togetherai Aug 6, 2025
60335a9
chore: remove reference to TOGETHER_API_KEY (#132)
tristandubbeld Aug 6, 2025
62da4fe
fix: Update to latest Ink and React 19 and bundle React and Ink into …
christianalfoni Aug 6, 2025
71b38b4
fix: Fix broken authorization in preview hosts
christianalfoni Aug 6, 2025
957c257
chore: automatic CLI rebuild on file change (#125)
tristandubbeld Aug 6, 2025
20a4e53
Merge pull request #141 from codesandbox/preview-hosts-auth
tristandubbeld Aug 6, 2025
db8aded
fix: Add retries to all idempotent endpoints and added parallel file …
christianalfoni Aug 6, 2025
207dd06
chore(main): release 2.0.6 (#139)
CompuIves Aug 6, 2025
8b69036
fix: also retry resume (#143)
christianalfoni Aug 6, 2025
fbb30a6
chore(main): release 2.0.7 (#144)
CompuIves Aug 6, 2025
a2f7de0
chore: Refactor to centralized API with retries for idempotent endpoi…
christianalfoni Aug 7, 2025
3a6f9ea
fix: Decouple pitcher-client (#148)
christianalfoni Aug 8, 2025
6050dbd
feat: add listRunning method to sandboxes namespace (#145)
christianalfoni Aug 8, 2025
b331315
feat: add open telemetry for sandboxes methods (#147)
christianalfoni Aug 8, 2025
2f58d43
feat: add fetching single sandbox (#142)
christianalfoni Aug 8, 2025
6ef2bf5
feat: add tracing to Sandbox and SandboxClient, also allow passing to…
christianalfoni Aug 8, 2025
6309b9b
add claude doc
christianalfoni Aug 8, 2025
dce7caf
feat: private sandbox, public hosts with public-hosts privacy (#154)
christianalfoni Aug 11, 2025
d386bda
Merge pull request #152 from codesandbox/claude
tristandubbeld Aug 12, 2025
a6f9fe7
feat: enhance container setup logging in build command
tristandubbeld Aug 13, 2025
ce3a282
fix: Add custom retry delay support for startVM API calls (#156)
christianalfoni Aug 13, 2025
9a3099f
fix: update log line length to be smaller
tristandubbeld Aug 13, 2025
836a7a6
Merge pull request #157 from codesandbox/tristan/csb-234-clarify-star…
tristandubbeld Aug 13, 2025
0def4a3
Increase frequency of keep active (#159)
christianalfoni Aug 13, 2025
f70903a
fix: include response handling in retries and dispose clients in buil…
christianalfoni Aug 14, 2025
017b905
handle isomorphic-ws building (#164)
christianalfoni Aug 19, 2025
9af1cdd
feat: Debug Sandboxes through CLI (#163)
christianalfoni Aug 19, 2025
cb2f330
fix: Stabilize websocket connection (#166)
christianalfoni Aug 20, 2025
6b50aaa
chore: add basic integration tests (#168)
christianalfoni Aug 21, 2025
029e3a5
fix: properly dispose and prevent wakeups (#170)
christianalfoni Aug 22, 2025
f9987b1
fix: friendly 503 error for overloaded Sandbox (#172)
christianalfoni Aug 22, 2025
e50a723
chore: fix version number (#173)
christianalfoni Aug 22, 2025
73e3e5c
chore(main): release 2.1.0 (#149)
CompuIves Aug 22, 2025
c5a8ffd
fix: Queue messages on lost connection and reconnect also on hibernat…
christianalfoni Aug 29, 2025
a9ec1a7
fix: prevent api config overrides (#177)
christianalfoni Aug 29, 2025
04381a0
fix: ensure private preview on private sandbox (#179)
christianalfoni Sep 1, 2025
493c5d5
feat: batch writes (#175)
christianalfoni Sep 2, 2025
b6f4846
feat: Add traceparent for all requests to API (#180)
christianalfoni Sep 2, 2025
ca0e02a
chore(main): release 2.2.0 (#178)
CompuIves Sep 2, 2025
d0bdf31
fix: Throw error when invalid port is used (#188)
christianalfoni Sep 16, 2025
7f6f7b4
chore(main): release 2.2.1 (#189)
CompuIves Sep 16, 2025
3f14843
fix: allow --help without api key (#190)
christianalfoni Sep 26, 2025
ce57736
New best practices release (#191)
christianalfoni Sep 26, 2025
93e65b3
feat: trigger release after squash merge (#195)
christianalfoni Sep 26, 2025
b5c6df9
fix: Remove devcontainer folder when .codesandbox/Dockerfile identifi…
christianalfoni Sep 29, 2025
8a4d86a
chore(main): release 2.3.0 (#194)
CompuIves Sep 29, 2025
489f033
chore: add pint openapi bundled json file (#198)
mohamedveron Oct 2, 2025
ddb42b0
initial ports implementation
christianalfoni Oct 2, 2025
199ec3f
basic exec run and list
christianalfoni Oct 8, 2025
6ec99e4
WIP: running execs
christianalfoni Oct 13, 2025
5d64302
next step
christianalfoni Oct 16, 2025
a4efb95
WIP
christianalfoni Oct 22, 2025
2415405
almost there
christianalfoni Nov 6, 2025
23fb42e
init fsclient imp
mohamedveron Nov 10, 2025
2a9404a
finish implementing the basic files and directories apis
mohamedveron Nov 11, 2025
a5bcf9d
add delete exec api
mohamedveron Nov 11, 2025
a5fafee
implement restart shell and send stdin apis
mohamedveron Nov 12, 2025
9d93f91
add rename file implementation
mohamedveron Nov 13, 2025
803a991
test rename file
mohamedveron Nov 13, 2025
6618575
add e2e pint <> pitcher compat tests
mojojoji Nov 14, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .codesandbox/ci.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
42 changes: 42 additions & 0 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Release Please

on:
push:
branches:
- main

permissions:
contents: write
pull-requests: write

jobs:
release-please:
runs-on: ubuntu-latest
steps:
- uses: googleapis/release-please-action@v4
id: release
with:
release-type: node
token: ${{ secrets.RELEASE_PLEASE_TOKEN }}
bump-minor-pre-major: true
bump-patch-for-minor-pre-major: true

- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: "20"
registry-url: "https://registry.npmjs.org"
cache: "npm"

- name: Install dependencies
run: npm install

- name: Build
run: npm run build

- name: Publish to NPM
if: ${{ steps.release.outputs.release_created }}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npm publish --no-git-checks
6 changes: 1 addition & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Generated stuff
dist
tests
test-template

### macOS ###
*.DS_Store
Expand Down Expand Up @@ -99,8 +99,4 @@ typings/
!.vscode/launch.json
!.vscode/extensions.json

# Lock files
package-lock.json
yarn.lock

# End of https://www.gitignore.io/api/node,visualstudiocode,macos
1 change: 1 addition & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
248 changes: 248 additions & 0 deletions CHANGELOG.md

Large diffs are not rendered by default.

134 changes: 134 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Development Commands

### Build Commands

- `npm run build` - Full production build (clean, esbuild, generate types for both CJS and ESM)
- `npm run build:esbuild` - Run esbuild bundling only
- `npm run clean` - Remove dist directory
- `npm run dev:cli` - Development mode with file watching for CLI (watches src/bin)

### Type Checking and Linting

- `npm run typecheck` - Run TypeScript type checking without emitting files
- `npm run format` - Format code using Prettier

### CLI Development

- `npm run dev:cli` - Start development mode with file watching specifically for CLI changes
- The CLI binary is built to `dist/bin/codesandbox.mjs` and made executable
- CLI can be run with `./dist/bin/codesandbox.mjs` or just `csb` if installed globally

### API Client Generation

- `npm run build-openapi` - Generate API clients from production OpenAPI spec
- `npm run build-openapi:staging` - Generate API clients from staging OpenAPI spec
- Generated clients are placed in `src/api-clients/` directory

## Architecture

### Core Components

**SDK Entry Points:**

- `src/index.ts` - Main SDK export with `CodeSandbox` class
- `src/browser/index.ts` - Browser-specific SDK build
- `src/node/index.ts` - Node.js-specific SDK build

**Key Classes:**

- `CodeSandbox` - Main SDK class providing `sandboxes` and `hosts` properties
- `Sandboxes` (src/Sandboxes.ts) - Manages sandbox operations (create, list, get, fork)
- `Sandbox` (src/Sandbox.ts) - Individual sandbox instance with connection and session management
- `SandboxClient` (src/SandboxClient/index.ts) - High-level client for sandbox interactions
- `API` (src/API.ts) - Low-level API wrapper for all CodeSandbox REST endpoints

**Communication Layer:**

- `src/pitcher-protocol/` - WebSocket protocol definitions and message types for real-time sandbox communication
- `src/AgentClient/` - WebSocket client implementation for connecting to sandbox agents

**CLI:**

- `src/bin/main.tsx` - CLI entry point using Ink (React for CLI)
- `src/bin/commands/` - Individual CLI commands (build, sandbox, previewHosts, hostTokens)
- `src/bin/ui/` - Ink-based UI components for the interactive CLI

### Build System

**Multi-Format Output:**

- ESM build: `dist/esm/` (primary format, "type": "module")
- CommonJS build: `dist/cjs/` (compatibility)
- Browser build: Separate bundles with browser polyfills
- CLI build: Standalone executable with shebang

**Key Build Features:**

- esbuild for bundling with custom plugins for module replacement
- Separate TypeScript compilation for type definitions
- Browser polyfills for Node.js modules (os, path, crypto, etc.)
- External dependencies preserved except for CLI build which bundles React/Ink

### Type System

**Configuration:**

- Main tsconfig.json excludes `src/bin` and `src/api-clients`
- Separate build configs for CJS (`tsconfig.build-cjs.json`) and ESM (`tsconfig.build-esm.json`)
- Strict TypeScript configuration with comprehensive type checking

**Generated Types:**

- `src/api-clients/` contains auto-generated API clients and types from OpenAPI specs
- Multiple API client modules for different sandbox services (fs, git, shell, etc.)

### Authentication & Configuration

**API Authentication:**

- Requires CodeSandbox API token (CSB_API_KEY environment variable)
- Token creation: https://codesandbox.io/t/api
- Automatic User-Agent header injection with SDK version

**Environment Detection:**

- Automatic base URL inference based on API key format
- Support for different CodeSandbox environments (production, staging)

### Testing

The codebase includes a `test-template/` directory with a Vite + React + TypeScript template for SDK testing.

## Documentation

**SDK Documentation:** https://codesandbox.io/docs/sdk

**Contributing to Documentation:**

- Documentation source is located at https://github.com/codesandbox/docs
- SDK-specific docs are in `packages/projects-docs/pages/sdk/` folder
- Update documentation there when making changes to SDK functionality

## Key Patterns

**Error Handling:**

- `handleResponse` utility for consistent API error handling
- Retry logic with exponential backoff for critical operations
- OpenTelemetry tracing integration for observability

**Session Management:**

- Support for custom sessions with git credentials and environment variables
- Browser session creation for web-based sandbox interactions
- Automatic session cleanup and disposal

**Resource Management:**

- VM tier scaling and hibernation timeout management
- Cluster and bootup type tracking
- Agent version management and update detection
60 changes: 23 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ CodeSandbox SDK enables you to programmatically spin up development environments

Under the hood, the SDK uses the microVM infrastructure of CodeSandbox to spin up sandboxes. It supports:

- Starting fresh VMs within 4 seconds
- Snapshotting/restoring VMs (checkpointing) at any point in time
- With snapshot restore times of less than 2 seconds
- Cloning VMs within 3 seconds
- With snapshot restore times within 1 second
- Cloning VMs & Snapshots within 2 seconds
- Source control (git, GitHub, CodeSandbox SCM)
- Running any Dockerfile

Expand All @@ -23,58 +22,45 @@ To get started, install the SDK:
npm install @codesandbox/sdk
```

Then, create 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:
Create 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:

```javascript
import { CodeSandbox } from "@codesandbox/sdk";

// Create the client with your token
const sdk = new CodeSandbox(token);
const sdk = new CodeSandbox(process.env.CSB_API_KEY);
const sandbox = await sdk.sandboxes.create();
const client = await sandbox.connect();

// This creates a new sandbox by forking our default template sandbox.
// You can also pass in other template ids, or create your own template to fork from.
const sandbox = await sdk.sandbox.create();
const output = await client.commands.run("echo 'Hello World'");

// You can run JS code directly
await sandbox.shells.js.run("console.log(1+1)");
// Or Python code (if it's installed in the template)
await sandbox.shells.python.run("print(1+1)");
console.log(output); // Hello World
```

// Or anything else
await sandbox.shells.run("echo 'Hello, world!'");
## Efficient Sandbox Retrieval

// We have a FS API to interact with the filesystem
await sandbox.fs.writeTextFile("./hello.txt", "world");
When you need to retrieve metadata for specific sandboxes by their IDs, you can use the efficient retrieval methods instead of listing and filtering all sandboxes:

// And you can clone sandboxes! This does not only clone the filesystem, processes that are running in the original sandbox will also be cloned!
const sandbox2 = await sandbox.fork();
### Get Single Sandbox

// Check that the file is still there
await sandbox2.fs.readTextFile("./hello.txt");
```javascript
// Efficient single sandbox retrieval
const sandbox = await sdk.sandboxes.get("sandbox-id");
console.log(sandbox.title, sandbox.tags);
```

// You can also get the opened ports, with the URL to access those
console.log(sandbox2.ports.getOpenedPorts());
This method is significantly more efficient than using `list()` and filtering, especially for large organizations with thousands of sandboxes.

// Getting metrics...
const metrics = await sandbox2.getMetrics();
console.log(
`Memory: ${metrics.memory.usedKiB} KiB / ${metrics.memory.totalKiB} KiB`
);
console.log(`CPU: ${(metrics.cpu.used / metrics.cpu.cores) * 100}%`);
## Configuration

// 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.
await sandbox.hibernate();
await sandbox2.hibernate();
The SDK supports the following environment variables for configuration:

// Open the sandbox again
const resumedSandbox = await sdk.sandbox.open(sandbox.id);
```
- `CSB_API_KEY`: Your CodeSandbox API token for authentication

## CodeSandbox Integration

This 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.

You 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.
Build your own template that has all the dependencies you need (even running servers), and then use that template to create sandboxes from. This way, you can control the environment that the sandboxes run in.

## Example Use Cases

Expand All @@ -84,6 +70,6 @@ Code interpretation: Run code in a sandbox to interpret it. This way, you can ru

Development 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.

AI 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.
AI 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.

CI/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.
Loading