sandbox

package
v0.21.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 25, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SandboxWorkspace is the workspace directory inside the sandbox.
	SandboxWorkspace = "/sandbox/workspace" //nolint:gosec // not a credential
	// SandboxClaudeConfig is the Claude config directory inside the sandbox.
	SandboxClaudeConfig = "/sandbox/claude-config" //nolint:gosec // not a credential

	DefaultMaxCreateAttempts = 3
)

Variables

This section is empty.

Functions

func CheckGateway added in v0.10.0

func CheckGateway() error

CheckGateway verifies that an openshell gateway is already running. The gateway must be started externally (e.g. in CI via the action.yml steps) before invoking fullsend run.

func CollectLogs added in v0.5.0

func CollectLogs(name, source string) (string, error)

CollectLogs runs `openshell logs <name> --source <source> -n 0` and returns the log output. The -n 0 flag requests all available log lines (no limit). This is a host-side command that talks to the gateway — no SSH needed.

func Create

func Create(name string, providers []string, image, policy string) error

Create creates a persistent OpenShell sandbox and waits for it to be ready. It retries up to DefaultMaxCreateAttempts times with exponential backoff, deleting the failed sandbox between attempts.

func CreateWithRetry added in v0.11.0

func CreateWithRetry(name string, providers []string, image, policy string, maxAttempts int, readyTimeoutOverride time.Duration) error

CreateWithRetry creates a sandbox, retrying up to maxAttempts times with exponential backoff on failure. Between attempts the failed sandbox is deleted to avoid name conflicts. If readyTimeoutOverride is positive, it overrides the default ready timeout.

func Delete

func Delete(name string) error

Delete deletes a sandbox, returning any error for the caller to log.

func Download added in v0.8.0

func Download(sandboxName, remotePath, localPath string) error

Download copies a file or directory from a sandbox to the local machine. The localPath is always treated as a directory by openshell — for single-file downloads use DownloadFile instead.

func DownloadFile added in v0.8.0

func DownloadFile(sandboxName, remotePath, localPath string) error

DownloadFile copies a single file from a sandbox to a specific local path. openshell sandbox download always treats the destination as a directory, so this downloads to the parent directory and renames if the resulting filename differs from the desired local name.

func EnsureAvailable

func EnsureAvailable() error

EnsureAvailable checks that the openshell binary is in PATH.

func EnsureProvider

func EnsureProvider(name, providerType string, credentials, config map[string]string) error

EnsureProvider creates or updates a provider on the gateway. Credential values may contain ${VAR} references which are expanded from the host environment before being passed to openshell.

Credentials use the bare-key form (--credential KEY) so that secret values never appear on the process command line. The expanded values are injected into the child process environment, where openshell reads them directly. See https://docs.nvidia.com/openshell/latest/sandboxes/manage-providers#bare-key-form

func Exec added in v0.8.0

func Exec(sandboxName, command string, timeout time.Duration) (stdout, stderr string, exitCode int, err error)

Exec runs a command inside a sandbox and returns stdout, stderr, and exit code. It uses context.Background() internally. Use ExecContext for cancellation support.

func ExecContext added in v0.18.0

func ExecContext(ctx context.Context, sandboxName, command string, timeout time.Duration) (stdout, stderr string, exitCode int, err error)

ExecContext is like Exec but accepts a parent context for cancellation. Cancelling the parent (e.g. on SIGTERM) terminates the subprocess.

func ExecStreamReader added in v0.8.0

func ExecStreamReader(ctx context.Context, sandboxName, command string, timeout time.Duration, stderrW io.Writer) (io.ReadCloser, *exec.Cmd, context.CancelFunc, error)

ExecStreamReader runs a command inside a sandbox, returning an io.ReadCloser for stdout so the caller can parse structured output. Stderr is forwarded to the given writer. The caller must read stdout to completion, then call cmd.Wait().

The parent context is used as the base for the timeout context, so cancelling the parent (e.g. on SIGTERM) terminates the subprocess. This allows CLI-level signal handling to propagate into long-running sandbox commands.

func ExtractOutputFiles

func ExtractOutputFiles(sandboxName, remoteDir, localDir string) ([]string, error)

ExtractOutputFiles copies all files under a remote directory in the sandbox to a local output directory, preserving relative paths.

func SafeDownload added in v0.8.0

func SafeDownload(sandboxName, remoteDir, localDir string) error

SafeDownload copies a directory from a sandbox to the local machine and then sanitizes the result by removing dangerous symlinks (absolute or repo-escaping) and .git/hooks/.

func Upload added in v0.8.0

func Upload(sandboxName, localPath, remotePath string) error

Upload copies a local file or directory into a sandbox.

func UploadDir added in v0.8.6

func UploadDir(sandboxName, localPath, remotePath string) error

UploadDir uploads a local directory into a sandbox, preserving symlinks. openshell sandbox upload dereferences symlinks; this builds a local tarball with --no-dereference, uploads it, and extracts it in the sandbox.

func UploadFile added in v0.16.0

func UploadFile(sandboxName, localPath, remotePath string) error

UploadFile copies a single local file into a sandbox at a specific remote path. It checks if the remotePath is a file and if it is not it tries to fix it. This is because of `openshell sandbox upload` in a git environment. Check https://github.com/NVIDIA/OpenShell/issues/1740 for more information. When that gets addressed, this can go away.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL