Documentation
¶
Index ¶
- Constants
- func EnsureDaemon(ctx context.Context, appBaseDir, logFile string) error
- type Box
- func (sb *Box) CreateContainer(ctx context.Context) error
- func (sb *Box) Exec(ctx context.Context, shellCmd string, args ...string) (string, error)
- func (sb *Box) GetContainer(ctx context.Context) (*types.Container, error)
- func (sb *Box) Shell(ctx context.Context, env map[string]string, shellCmd string, stdin io.Reader, ...) error
- func (sb *Box) StartContainer(ctx context.Context) error
- func (sb *Box) Sync(ctx context.Context) error
- type Boxer
- func (sb *Boxer) AttachSandbox(ctx context.Context, id string) (*Box, error)
- func (sb *Boxer) Cleanup(ctx context.Context, sbox *Box) error
- func (sb *Boxer) Close() error
- func (sb *Boxer) EnsureImage(ctx context.Context, imageName string) error
- func (sb *Boxer) Get(ctx context.Context, id string) (*Box, error)
- func (sb *Boxer) List(ctx context.Context) ([]Box, error)
- func (sb *Boxer) NewSandbox(ctx context.Context, cloner WorkspaceCloner, ...) (*Box, error)
- func (sb *Boxer) SaveSandbox(ctx context.Context, sbox *Box) error
- func (sb *Boxer) StopContainer(ctx context.Context, sbox *Box) error
- func (sb *Boxer) Sync(ctx context.Context) error
- func (sb *Boxer) UpdateContainerID(ctx context.Context, sbox *Box, containerID string) error
- type ClaudeWorkspaceCloner
- type CloneRequest
- type CloneResult
- type ContainerOps
- type ContainerStartupHook
- type CreateSandboxOpts
- type DefaultWorkspaceCloner
- type FileOps
- type GitOps
- type HostMCP
- type ImageOps
- type MountSpec
- type Mux
- func (m *Mux) CreateSandbox(ctx context.Context, opts CreateSandboxOpts) (*Box, error)
- func (m *Mux) GetSandbox(ctx context.Context, id string) (*Box, error)
- func (m *Mux) ListSandboxes(ctx context.Context) ([]Box, error)
- func (m *Mux) NewClient(ctx context.Context) (*MuxClient, error)
- func (m *Mux) RemoveSandbox(ctx context.Context, id string) error
- func (m *Mux) ServeUnixSocket(ctx context.Context) error
- func (m *Mux) Shutdown(ctx context.Context)
- func (m *Mux) StopSandbox(ctx context.Context, id string) error
- type MuxClient
- func (m *MuxClient) CreateSandbox(ctx context.Context, opts CreateSandboxOpts) (*Box, error)
- func (m *MuxClient) GetSandbox(ctx context.Context, id string) (*Box, error)
- func (m *MuxClient) ListSandboxes(ctx context.Context) ([]Box, error)
- func (m *MuxClient) Ping(ctx context.Context) error
- func (m *MuxClient) RemoveSandbox(ctx context.Context, id string) error
- func (m *MuxClient) Shutdown(ctx context.Context) error
- func (m *MuxClient) StopSandbox(ctx context.Context, id string) error
- func (m *MuxClient) Version(ctx context.Context) (version.Info, error)
- type OpenCodeWorkspaceCloner
- type UserMessenger
- type WorkspaceCloner
- func NewClaudeWorkspaceCloner(baseCloner WorkspaceCloner, appRoot string, terminalWriter io.Writer) WorkspaceCloner
- func NewDefaultWorkspaceCloner(appRoot string, terminalWriter io.Writer) WorkspaceCloner
- func NewOpenCodeWorkspaceCloner(baseCloner WorkspaceCloner, appRoot string, terminalWriter io.Writer) WorkspaceCloner
Constants ¶
const (
ClonedWorkDirGitRemotePrefix = "sand/"
)
const (
DefaultImageName = "ghcr.io/banksean/sand/default:latest"
)
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Box ¶
type Box struct {
// ID is an opaque identifier for the sandbox
ID string
// ContainerID is the ID of the container
ContainerID string
// HostOriginDir is the origin of the sandbox, from which we clone its contents
HostOriginDir string
// SandboxWorkDir is the host OS filesystem path containing the sandbox's c-o-w clone of hostOriginDir.
SandboxWorkDir string
// ImageName is the name of the container image
ImageName string
// DNSDomain is the dns domain for the sandbox's network
DNSDomain string
// EnvFile is the host filesystem path to the env file to use when executing commands in the container
EnvFile string
// Mounts defines bind mounts that should be attached when creating the container.
Mounts []MountSpec
// SandboxWorkDirError and SandboxContainerError are the most recently updated error states of the sandbox
// work dir and container instance. In-memory only. Updated once either at
// server startup or sandbox creation time, and then updated periodically thereafter.
// Empty string implies things are ok.
// TODO: Make sandbox operations conditional on these values, so that e.g. you don't try to start
// a sandbox container instance if the sandbox's work dir is not available.
SandboxWorkDirError string
SandboxContainerError string
// ContainerHooks run after the container has started to perform any bootstrap logic.
ContainerHooks []ContainerStartupHook `json:"-"`
Keys *sshimmer.Keys
// contains filtered or unexported fields
}
Box is a "sandbox" - it represents the connection between - a local filesystem clone of a local dev workspace directory - a local container instance (whose state is managed by a separate container service)
At startup, the sand.Mux server will synchronize its internal database with the current observed state of the local filesystem clone root and the local container service.
func (*Box) CreateContainer ¶
CreateContainer creates a new container instance. The container image must exist.
func (*Box) Exec ¶
Exec executes a command in the container. The container must be in state "running".
func (*Box) GetContainer ¶
func (*Box) Shell ¶
func (sb *Box) Shell(ctx context.Context, env map[string]string, shellCmd string, stdin io.Reader, stdout, stderr io.Writer) error
Shell executes a command in the container. The container must be in state "running".
func (*Box) StartContainer ¶
StartContainer starts a container instance. The container must exist, and it should not be in the "running" state.
type Boxer ¶
type Boxer struct {
// contains filtered or unexported fields
}
Boxer manages the lifecycle of sandboxes.
func (*Boxer) AttachSandbox ¶
AttachSandbox re-connects to an existing container and sandboxWorkDir instead of creating a new one.
func (*Boxer) EnsureImage ¶
EnsureImage makes sure the requested container image is present locally, pulling it if required.
func (*Boxer) NewSandbox ¶
func (sb *Boxer) NewSandbox(ctx context.Context, cloner WorkspaceCloner, id, hostWorkDir, imageName, envFile string) (*Box, error)
NewSandbox creates a new sandbox based on a clone of hostWorkDir. TODO: clone envFile, if it exists, into the sandbox clone so every command exec'd in that sandbox container uses the same env file, even if the original .env file has changed on the host machine.
func (*Boxer) SaveSandbox ¶
SaveSandbox persists the Sandbox to the database.
func (*Boxer) StopContainer ¶
StopContainer stops a sandbox's container without deleting it.
type ClaudeWorkspaceCloner ¶
type ClaudeWorkspaceCloner struct {
// contains filtered or unexported fields
}
func (*ClaudeWorkspaceCloner) Hydrate ¶
func (c *ClaudeWorkspaceCloner) Hydrate(ctx context.Context, box *Box) error
func (*ClaudeWorkspaceCloner) Prepare ¶
func (c *ClaudeWorkspaceCloner) Prepare(ctx context.Context, req CloneRequest) (*CloneResult, error)
type CloneRequest ¶
CloneRequest captures the inputs necessary to prepare a sandbox workspace.
type CloneResult ¶
type CloneResult struct {
SandboxWorkDir string
Mounts []MountSpec
ContainerHooks []ContainerStartupHook
}
CloneResult describes the assets created for a sandbox and how to mount/configure them.
type ContainerOps ¶
type ContainerOps interface {
Create(ctx context.Context, opts *options.CreateContainer, image string, args []string) (string, error)
Start(ctx context.Context, opts *options.StartContainer, containerID string) (string, error)
Stop(ctx context.Context, opts *options.StopContainer, containerID string) (string, error)
Delete(ctx context.Context, opts *options.DeleteContainer, containerID string) (string, error)
Exec(ctx context.Context, opts *options.ExecContainer, containerID, cmd string, env []string, args ...string) (string, error)
ExecStream(ctx context.Context, opts *options.ExecContainer, containerID, cmd string, env []string, stdin io.Reader, stdout, stderr io.Writer) (func() error, error)
Inspect(ctx context.Context, containerID string) ([]types.Container, error)
}
func NewAppleContainerOps ¶
func NewAppleContainerOps() ContainerOps
type ContainerStartupHook ¶
ContainerStartupHook allows callers to inject container startup customisation.
func NewContainerStartupHook ¶
func NewContainerStartupHook(name string, fn func(ctx context.Context, b *Box) error) ContainerStartupHook
NewContainerStartupHook helpers callers construct hook instances without exporting internals.
type CreateSandboxOpts ¶
type DefaultWorkspaceCloner ¶
type DefaultWorkspaceCloner struct {
// contains filtered or unexported fields
}
DefaultWorkspaceCloner reproduces the current cloning behaviour.
func (*DefaultWorkspaceCloner) Hydrate ¶
func (p *DefaultWorkspaceCloner) Hydrate(ctx context.Context, box *Box) error
Hydrate populates runtime-only fields on a Box that was loaded from persistent storage.
func (*DefaultWorkspaceCloner) Prepare ¶
func (p *DefaultWorkspaceCloner) Prepare(ctx context.Context, req CloneRequest) (*CloneResult, error)
type FileOps ¶
type FileOps interface {
MkdirAll(path string, perm os.FileMode) error
Copy(ctx context.Context, src, dst string) error
Stat(path string) (os.FileInfo, error)
Lstat(path string) (os.FileInfo, error)
Readlink(path string) (string, error)
Create(path string) (*os.File, error)
RemoveAll(path string) error
WriteFile(path string, data []byte, perm os.FileMode) error
}
func NewDefaultFileOps ¶
func NewDefaultFileOps() FileOps
type GitOps ¶
type GitOps interface {
AddRemote(ctx context.Context, dir, name, url string) error
RemoveRemote(ctx context.Context, dir, name string) error
Fetch(ctx context.Context, dir, remote string) error
TopLevel(ctx context.Context, dir string) string
}
func NewDefaultGitOps ¶
func NewDefaultGitOps() GitOps
type HostMCP ¶
type ImageOps ¶
type ImageOps interface {
List(ctx context.Context) ([]types.ImageEntry, error)
Pull(ctx context.Context, image string) (func() error, error)
}
func NewAppleImageOps ¶
func NewAppleImageOps() ImageOps
type Mux ¶
func NewMuxServer ¶
func (*Mux) CreateSandbox ¶
CreateSandbox creates a new sandbox and starts its container.
func (*Mux) GetSandbox ¶
GetSandbox retrieves a sandbox by ID.
func (*Mux) ListSandboxes ¶
ListSandboxes returns all sandboxes.
func (*Mux) RemoveSandbox ¶
RemoveSandbox removes a single sandbox.
func (*Mux) ServeUnixSocket ¶
ServeUnixSocket serves the unix domain socket that sandmux clients (the CLI, e.g.) connect to.
type MuxClient ¶
type MuxClient struct {
Mux *Mux
// contains filtered or unexported fields
}
func (*MuxClient) CreateSandbox ¶
func (*MuxClient) GetSandbox ¶
func (*MuxClient) ListSandboxes ¶
func (*MuxClient) RemoveSandbox ¶
func (*MuxClient) StopSandbox ¶
type OpenCodeWorkspaceCloner ¶
type OpenCodeWorkspaceCloner struct {
// contains filtered or unexported fields
}
func (*OpenCodeWorkspaceCloner) Hydrate ¶
func (c *OpenCodeWorkspaceCloner) Hydrate(ctx context.Context, box *Box) error
func (*OpenCodeWorkspaceCloner) Prepare ¶
func (c *OpenCodeWorkspaceCloner) Prepare(ctx context.Context, req CloneRequest) (*CloneResult, error)
type UserMessenger ¶
func NewNullMessenger ¶
func NewNullMessenger() UserMessenger
func NewTerminalMessenger ¶
func NewTerminalMessenger(writer io.Writer) UserMessenger
type WorkspaceCloner ¶
type WorkspaceCloner interface {
Prepare(ctx context.Context, req CloneRequest) (*CloneResult, error)
// BUG: Hydrate isn't getting called anywhere, so extra container startup hooks aren't getting registered or invoked.
Hydrate(ctx context.Context, box *Box) error
}
WorkspaceCloner abstracts the steps for preparing sandbox host resources.
func NewClaudeWorkspaceCloner ¶
func NewClaudeWorkspaceCloner(baseCloner WorkspaceCloner, appRoot string, terminalWriter io.Writer) WorkspaceCloner
func NewDefaultWorkspaceCloner ¶
func NewDefaultWorkspaceCloner(appRoot string, terminalWriter io.Writer) WorkspaceCloner
NewDefaultWorkspaceCloner constructs the default provisioner used by Boxer.
func NewOpenCodeWorkspaceCloner ¶
func NewOpenCodeWorkspaceCloner(baseCloner WorkspaceCloner, appRoot string, terminalWriter io.Writer) WorkspaceCloner
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
package applecontainer implements helper functions and types for use with apple's container library.
|
package applecontainer implements helper functions and types for use with apple's container library. |
|
options
package options defines structs for the flagsets passed to various `container` commands.
|
package options defines structs for the flagsets passed to various `container` commands. |
|
types
package types defines structs for unmashaling the output from various `container` commands.
|
package types defines structs for unmashaling the output from various `container` commands. |
|
cmd
|
|
|
sand
command
|
|