Go SDK for creating and controlling E2B sandboxes from Go.
This repository provides the root e2b package plus lower-level packages for commands, filesystem access, Git, templates, volumes, and API clients. It also contains the documentation source under docs/ and compile-checked doc examples in internal/doctest/.
- Create or connect to Linux sandboxes
- Run foreground or background commands
- Read, write, upload, download, and watch files
- Open PTY sessions
- Use Git inside a sandbox
- Create and mount persistent volumes
- Build reusable E2B templates from Go
- Go
1.22+ - An E2B API key in
E2B_API_KEY
Optional environment variables:
E2B_ACCESS_TOKENE2B_DOMAINE2B_API_URLE2B_SANDBOX_URLE2B_DEBUG
go get github.com/superduck-ai/e2b-go-sdkSet your API key first:
export E2B_API_KEY=e2b_***Create a sandbox, run a command, and inspect the filesystem:
package main
import (
"context"
"log"
e2b "github.com/superduck-ai/e2b-go-sdk"
)
func main() {
ctx := context.Background()
sandbox, err := e2b.Create(ctx, "", nil)
if err != nil {
log.Fatal(err)
}
defer sandbox.Kill(context.Background(), nil)
execution, err := sandbox.Commands.Run(ctx, `python3 -c "print('hello world')"`, nil)
if err != nil {
log.Fatal(err)
}
result := execution.(*e2b.CommandResult)
entries, err := sandbox.Files.List(ctx, "/", nil)
if err != nil {
log.Fatal(err)
}
log.Println(result.Stdout)
log.Println(entries)
}e2b.Create(ctx, template, opts)creates a sandboxe2b.Connect(ctx, sandboxID, opts)reconnects to an existing sandboxsandbox.Commands.Run(ctx, cmd, opts)runs commandssandbox.Files.Read/Write/List(...)works with files inside the sandboxsandbox.Pty.Create(ctx, opts)starts an interactive PTY sessionsandbox.Gitexposes Git operations inside the sandboxe2b.CreateVolume(...)and related helpers manage persistent volumese2b.Template(...)ande2b.Build(...)define and build templates
The root package re-exports most commonly used command, filesystem, Git, template, and volume types so application code can stay in the e2b package for the common path.
Run the default test suite:
go test ./...Run the documentation validation suite only:
go test ./internal/doctest -run '^TestDocs' -count=1Run integration tests against a live E2B account:
E2B_API_KEY=e2b_*** go test -tags=integration ./...Some expensive stress cases are skipped unless you opt in with additional environment variables such as E2B_RUN_STRESS=1.
sandbox.go: sandbox lifecycle and runtime entry pointscommands/: command execution and PTY supportfilesystem/: sandbox filesystem APIsgit/: Git helpers for sandbox workflowstemplate/: template authoring and build APIsvolume/: persistent volume APIsapi/: lower-level control plane clientdocs/: documentation pagesinternal/doctest/: compile-checked documentation examples plus link/asset/snippet audits
The repository documentation lives in:
If you change public behavior, update the corresponding doc page and matching coverage in internal/doctest/ in the same change.