options
Section titled “options”import "github.com/daytonaio/daytona/libs/sdk-go/pkg/options"Package options provides functional option types for configuring SDK operations.
This package uses the functional options pattern to provide a clean, extensible API for configuring optional parameters. Each option function returns a closure that modifies the corresponding options struct.
Options are passed as variadic arguments to SDK methods:
err := sandbox.Git.Clone(ctx, url, path, options.WithBranch("develop"), options.WithUsername("user"), options.WithPassword("token"),)Generic Apply Function
Section titled “Generic Apply Function”The Apply function creates a new options struct and applies all provided option functions to it:
opts := options.Apply( options.WithBranch("main"), options.WithUsername("user"),)// opts.Branch == "main", opts.Username == "user"- func Apply[T any](opts …func(*T)) *T
- func WithAllowEmpty(allowEmpty bool) func(*GitCommit)
- func WithBranch(branch string) func(*GitClone)
- func WithCodeRunLanguage(language types.CodeLanguage) func(*CodeRun)
- func WithCodeRunParams(params types.CodeRunParams) func(*CodeRun)
- func WithCodeRunTimeout(timeout time.Duration) func(*CodeRun)
- func WithCommandEnv(env map[string]string) func(*ExecuteCommand)
- func WithCommitId(commitID string) func(*GitClone)
- func WithCreatePtyEnv(env map[string]string) func(*CreatePty)
- func WithCreatePtySize(ptySize types.PtySize) func(*CreatePty)
- func WithCustomContext(contextID string) func(*RunCode)
- func WithCwd(cwd string) func(*ExecuteCommand)
- func WithEnv(env map[string]string) func(*RunCode)
- func WithExecuteTimeout(timeout time.Duration) func(*ExecuteCommand)
- func WithExtraIndexURLs(urls …string) func(*PipInstall)
- func WithExtraOptions(options string) func(*PipInstall)
- func WithFindLinks(links …string) func(*PipInstall)
- func WithForce(force bool) func(*GitDeleteBranch)
- func WithGroup(group string) func(*SetFilePermissions)
- func WithIndexURL(url string) func(*PipInstall)
- func WithInterpreterTimeout(timeout time.Duration) func(*RunCode)
- func WithLogChannel(logChannel chan string) func(*CreateSandbox)
- func WithMode(mode string) func(*CreateFolder)
- func WithOwner(owner string) func(*SetFilePermissions)
- func WithPassword(password string) func(*GitClone)
- func WithPermissionMode(mode string) func(*SetFilePermissions)
- func WithPre() func(*PipInstall)
- func WithPtyEnv(env map[string]string) func(*PtySession)
- func WithPtySize(size types.PtySize) func(*PtySession)
- func WithPullPassword(password string) func(*GitPull)
- func WithPullUsername(username string) func(*GitPull)
- func WithPushPassword(password string) func(*GitPush)
- func WithPushUsername(username string) func(*GitPush)
- func WithTimeout(timeout time.Duration) func(*CreateSandbox)
- func WithUsername(username string) func(*GitClone)
- func WithWaitForStart(waitForStart bool) func(*CreateSandbox)
- type CodeRun
- type CreateFolder
- type CreatePty
- type CreateSandbox
- type ExecuteCommand
- type GitClone
- type GitCommit
- type GitDeleteBranch
- type GitPull
- type GitPush
- type PipInstall
- type PtySession
- type RunCode
- type SetFilePermissions
func Apply
Section titled “func Apply”func Apply[T any](opts ...func(*T)) *TApply creates a new instance of type T and applies all provided option functions.
This generic function enables a consistent pattern for applying functional options across different option types. It allocates a zero-value instance of T, then applies each option function in order.
Example:
opts := options.Apply( options.WithBranch("main"), options.WithUsername("user"),)func WithAllowEmpty
Section titled “func WithAllowEmpty”func WithAllowEmpty(allowEmpty bool) func(*GitCommit)WithAllowEmpty allows creating a commit even when there are no staged changes.
This is useful for triggering CI/CD pipelines or marking points in history without actual code changes.
Example:
resp, err := sandbox.Git.Commit(ctx, path, "Trigger rebuild", author, email, options.WithAllowEmpty(true),)func WithBranch
Section titled “func WithBranch”func WithBranch(branch string) func(*GitClone)WithBranch sets the branch to clone instead of the repository’s default branch.
Example:
err := sandbox.Git.Clone(ctx, url, path, options.WithBranch("develop"))func WithCodeRunLanguage
Section titled “func WithCodeRunLanguage”func WithCodeRunLanguage(language types.CodeLanguage) func(*CodeRun)func WithCodeRunParams
Section titled “func WithCodeRunParams”func WithCodeRunParams(params types.CodeRunParams) func(*CodeRun)WithCodeRunParams sets the code execution parameters.
Example:
result, err := sandbox.Process.CodeRun(ctx, code, options.WithCodeRunParams(types.CodeRunParams{Language: "python"}),)func WithCodeRunTimeout
Section titled “func WithCodeRunTimeout”func WithCodeRunTimeout(timeout time.Duration) func(*CodeRun)func WithCommandEnv
Section titled “func WithCommandEnv”func WithCommandEnv(env map[string]string) func(*ExecuteCommand)WithCommandEnv sets environment variables for the command.
These variables are added to the command’s environment in addition to the sandbox’s default environment.
Example:
result, err := sandbox.Process.ExecuteCommand(ctx, "echo $MY_VAR", options.WithCommandEnv(map[string]string{"MY_VAR": "hello"}),)func WithCommitId
Section titled “func WithCommitId”func WithCommitId(commitID string) func(*GitClone)WithCommitId sets a specific commit SHA to checkout after cloning.
The repository is first cloned, then the specified commit is checked out, resulting in a detached HEAD state.
Example:
err := sandbox.Git.Clone(ctx, url, path, options.WithCommitId("abc123def"))func WithCreatePtyEnv
Section titled “func WithCreatePtyEnv”func WithCreatePtyEnv(env map[string]string) func(*CreatePty)WithCreatePtyEnv sets environment variables for CreatePty.
Example:
handle, err := sandbox.Process.CreatePty(ctx, "my-pty", options.WithCreatePtyEnv(map[string]string{"TERM": "xterm-256color"}),)func WithCreatePtySize
Section titled “func WithCreatePtySize”func WithCreatePtySize(ptySize types.PtySize) func(*CreatePty)WithCreatePtySize sets the PTY terminal dimensions for CreatePty.
Example:
handle, err := sandbox.Process.CreatePty(ctx, "my-pty", options.WithCreatePtySize(types.PtySize{Rows: 24, Cols: 80}),)func WithCustomContext
Section titled “func WithCustomContext”func WithCustomContext(contextID string) func(*RunCode)WithCustomContext sets the interpreter context ID for code execution.
Using a context allows you to maintain state (variables, imports, etc.) across multiple code executions. Create a context with CreateContext first.
Example:
ctx, _ := sandbox.CodeInterpreter.CreateContext(ctx, nil)channels, err := sandbox.CodeInterpreter.RunCode(ctx, "x = 42", options.WithCustomContext(ctx["id"].(string)),)func WithCwd
Section titled “func WithCwd”func WithCwd(cwd string) func(*ExecuteCommand)WithCwd sets the working directory for command execution.
Example:
result, err := sandbox.Process.ExecuteCommand(ctx, "ls -la", options.WithCwd("/home/user/project"),)func WithEnv
Section titled “func WithEnv”func WithEnv(env map[string]string) func(*RunCode)WithEnv sets environment variables for code execution.
These variables are available to the code during execution.
Example:
channels, err := sandbox.CodeInterpreter.RunCode(ctx, "import os; print(os.environ['API_KEY'])", options.WithEnv(map[string]string{"API_KEY": "secret"}),)func WithExecuteTimeout
Section titled “func WithExecuteTimeout”func WithExecuteTimeout(timeout time.Duration) func(*ExecuteCommand)WithExecuteTimeout sets the timeout for command execution.
If the command doesn’t complete within the timeout, it will be terminated.
Example:
result, err := sandbox.Process.ExecuteCommand(ctx, "sleep 60", options.WithExecuteTimeout(5*time.Second),)func WithExtraIndexURLs
Section titled “func WithExtraIndexURLs”func WithExtraIndexURLs(urls ...string) func(*PipInstall)WithExtraIndexURLs adds extra index URLs for pip install.
Extra indexes are checked in addition to the main index URL. Useful for installing packages from both PyPI and a private index.
Example:
image := daytona.Base("python:3.11").PipInstall( []string{"mypackage"}, options.WithExtraIndexURLs("https://private.example.com/simple/"),)func WithExtraOptions
Section titled “func WithExtraOptions”func WithExtraOptions(options string) func(*PipInstall)WithExtraOptions adds extra command-line options for pip install.
Use this for pip options not covered by other With* functions.
Example:
image := daytona.Base("python:3.11").PipInstall( []string{"mypackage"}, options.WithExtraOptions("--no-cache-dir --upgrade"),)func WithFindLinks
Section titled “func WithFindLinks”func WithFindLinks(links ...string) func(*PipInstall)WithFindLinks adds find-links URLs for pip install.
Find-links URLs are searched for packages before the package index. Useful for installing packages from local directories or custom URLs.
Example:
image := daytona.Base("python:3.11").PipInstall( []string{"mypackage"}, options.WithFindLinks("/path/to/wheels", "https://example.com/wheels/"),)func WithForce
Section titled “func WithForce”func WithForce(force bool) func(*GitDeleteBranch)WithForce enables force deletion of a branch even if it’s not fully merged.
Use with caution as this can result in lost commits if the branch contains work that hasn’t been merged elsewhere.
Example:
err := sandbox.Git.DeleteBranch(ctx, path, "feature/abandoned", options.WithForce(true),)func WithGroup
Section titled “func WithGroup”func WithGroup(group string) func(*SetFilePermissions)WithGroup sets the file group.
The group should be a valid group name on the sandbox system.
Example:
err := sandbox.FileSystem.SetFilePermissions(ctx, "/home/user/file.txt", options.WithGroup("users"),)func WithIndexURL
Section titled “func WithIndexURL”func WithIndexURL(url string) func(*PipInstall)WithIndexURL sets the base URL of the Python Package Index.
Replaces the default PyPI (https://pypi.org/simple\) with a custom index.
Example:
image := daytona.Base("python:3.11").PipInstall( []string{"mypackage"}, options.WithIndexURL("https://my-pypi.example.com/simple/"),)func WithInterpreterTimeout
Section titled “func WithInterpreterTimeout”func WithInterpreterTimeout(timeout time.Duration) func(*RunCode)WithInterpreterTimeout sets the execution timeout for code.
If the code doesn’t complete within the timeout, execution is terminated.
Example:
channels, err := sandbox.CodeInterpreter.RunCode(ctx, "import time; time.sleep(60)", options.WithInterpreterTimeout(5*time.Second),)func WithLogChannel
Section titled “func WithLogChannel”func WithLogChannel(logChannel chan string) func(*CreateSandbox)WithLogChannel provides a channel for receiving build logs during sandbox creation.
When creating a sandbox from a custom image that requires building, build logs are streamed to the provided channel. The channel is closed when streaming completes. If no build is required, no logs are sent and the channel remains unused.
Example:
logChan := make(chan string)go func() { for log := range logChan { fmt.Println(log) }}()sandbox, err := client.Create(ctx, params, options.WithLogChannel(logChan),)func WithMode
Section titled “func WithMode”func WithMode(mode string) func(*CreateFolder)WithMode sets the Unix file permissions for the created folder.
The mode should be specified as an octal string (e.g., “0755”, “0700”). If not specified, defaults to “0755”.
Example:
err := sandbox.FileSystem.CreateFolder(ctx, "/home/user/mydir", options.WithMode("0700"),)func WithOwner
Section titled “func WithOwner”func WithOwner(owner string) func(*SetFilePermissions)WithOwner sets the file owner.
The owner should be a valid username on the sandbox system.
Example:
err := sandbox.FileSystem.SetFilePermissions(ctx, "/home/user/file.txt", options.WithOwner("root"),)func WithPassword
Section titled “func WithPassword”func WithPassword(password string) func(*GitClone)WithPassword sets the password or access token for HTTPS authentication when cloning.
For GitHub, use a Personal Access Token (PAT). For GitLab, use a Project Access Token or Personal Access Token. For Bitbucket, use an App Password.
Example:
err := sandbox.Git.Clone(ctx, url, path, options.WithUsername("username"), options.WithPassword("ghp_xxxxxxxxxxxx"),)func WithPermissionMode
Section titled “func WithPermissionMode”func WithPermissionMode(mode string) func(*SetFilePermissions)WithPermissionMode sets the Unix file permissions.
The mode should be specified as an octal string (e.g., “0644”, “0755”).
Example:
err := sandbox.FileSystem.SetFilePermissions(ctx, "/home/user/file.txt", options.WithPermissionMode("0644"),)func WithPre
Section titled “func WithPre”func WithPre() func(*PipInstall)WithPre enables installation of pre-release and development versions.
Example:
image := daytona.Base("python:3.11").PipInstall( []string{"mypackage"}, options.WithPre(),)func WithPtyEnv
Section titled “func WithPtyEnv”func WithPtyEnv(env map[string]string) func(*PtySession)WithPtyEnv sets environment variables for the PTY session.
Example:
session, err := sandbox.Process.CreatePtySession(ctx, "my-session", options.WithPtyEnv(map[string]string{"TERM": "xterm-256color"}),)func WithPtySize
Section titled “func WithPtySize”func WithPtySize(size types.PtySize) func(*PtySession)WithPtySize sets the PTY terminal dimensions.
Example:
session, err := sandbox.Process.CreatePtySession(ctx, "my-session", options.WithPtySize(types.PtySize{Rows: 24, Cols: 80}),)func WithPullPassword
Section titled “func WithPullPassword”func WithPullPassword(password string) func(*GitPull)WithPullPassword sets the password or access token for HTTPS authentication when pulling.
Example:
err := sandbox.Git.Pull(ctx, path, options.WithPullUsername("username"), options.WithPullPassword("ghp_xxxxxxxxxxxx"),)func WithPullUsername
Section titled “func WithPullUsername”func WithPullUsername(username string) func(*GitPull)WithPullUsername sets the username for HTTPS authentication when pulling.
Example:
err := sandbox.Git.Pull(ctx, path, options.WithPullUsername("username"), options.WithPullPassword("github_token"),)func WithPushPassword
Section titled “func WithPushPassword”func WithPushPassword(password string) func(*GitPush)WithPushPassword sets the password or access token for HTTPS authentication when pushing.
Example:
err := sandbox.Git.Push(ctx, path, options.WithPushUsername("username"), options.WithPushPassword("ghp_xxxxxxxxxxxx"),)func WithPushUsername
Section titled “func WithPushUsername”func WithPushUsername(username string) func(*GitPush)WithPushUsername sets the username for HTTPS authentication when pushing.
Example:
err := sandbox.Git.Push(ctx, path, options.WithPushUsername("username"), options.WithPushPassword("github_token"),)func WithTimeout
Section titled “func WithTimeout”func WithTimeout(timeout time.Duration) func(*CreateSandbox)WithTimeout sets the maximum duration to wait for sandbox creation to complete.
If the timeout is exceeded before the sandbox is ready, Create returns an error. The default timeout is 60 seconds.
Example:
sandbox, err := client.Create(ctx, params, options.WithTimeout(5*time.Minute),)func WithUsername
Section titled “func WithUsername”func WithUsername(username string) func(*GitClone)WithUsername sets the username for HTTPS authentication when cloning.
For GitHub, GitLab, and similar services, the username is typically your account username or a placeholder like “git” when using tokens.
Example:
err := sandbox.Git.Clone(ctx, url, path, options.WithUsername("username"), options.WithPassword("github_token"),)func WithWaitForStart
Section titled “func WithWaitForStart”func WithWaitForStart(waitForStart bool) func(*CreateSandbox)WithWaitForStart controls whether [daytona.Client.Create] waits for the sandbox to reach the started state before returning.
When true (the default), Create blocks until the sandbox is fully started and ready for use. When false, Create returns immediately after the sandbox is created, which may be in a pending or building state.
Example:
// Return immediately without waiting for the sandbox to startsandbox, err := client.Create(ctx, params, options.WithWaitForStart(false),)type CodeRun
Section titled “type CodeRun”CodeRun holds optional parameters for [daytona.ProcessService.CodeRun].
type CodeRun struct { Params *types.CodeRunParams // Code execution parameters Timeout *time.Duration // Execution timeout Language types.CodeLanguage // Override the default language}type CreateFolder
Section titled “type CreateFolder”CreateFolder holds optional parameters for [daytona.FileSystemService.CreateFolder].
type CreateFolder struct { Mode *string // Unix file permissions (e.g., "0755")}type CreatePty
Section titled “type CreatePty”CreatePty holds optional parameters for [daytona.ProcessService.CreatePty].
type CreatePty struct { PtySize *types.PtySize // Terminal dimensions (rows and columns) Env map[string]string // Environment variables for the PTY session}type CreateSandbox
Section titled “type CreateSandbox”CreateSandbox holds optional parameters for [daytona.Client.Create].
type CreateSandbox struct { Timeout *time.Duration // Maximum time to wait for sandbox creation WaitForStart bool // Whether to wait for the sandbox to reach started state LogChannel chan string // Channel for receiving build logs during image builds}type ExecuteCommand
Section titled “type ExecuteCommand”ExecuteCommand holds optional parameters for [daytona.ProcessService.ExecuteCommand].
type ExecuteCommand struct { Cwd *string // Working directory for command execution Env map[string]string // Environment variables Timeout *time.Duration // Command execution timeout}type GitClone
Section titled “type GitClone”GitClone holds optional parameters for [daytona.GitService.Clone].
Fields are pointers to distinguish between unset values and zero values. Use the corresponding With* functions to set these options.
type GitClone struct { Branch *string // Branch to clone (defaults to repository's default branch) CommitId *string // Specific commit SHA to checkout after cloning Username *string // Username for HTTPS authentication Password *string // Password or token for HTTPS authentication}type GitCommit
Section titled “type GitCommit”GitCommit holds optional parameters for [daytona.GitService.Commit].
type GitCommit struct { AllowEmpty *bool // Allow creating commits with no staged changes}type GitDeleteBranch
Section titled “type GitDeleteBranch”GitDeleteBranch holds optional parameters for [daytona.GitService.DeleteBranch].
type GitDeleteBranch struct { Force *bool // Force delete even if branch is not fully merged}type GitPull
Section titled “type GitPull”GitPull holds optional parameters for [daytona.GitService.Pull].
type GitPull struct { Username *string // Username for HTTPS authentication Password *string // Password or token for HTTPS authentication}type GitPush
Section titled “type GitPush”GitPush holds optional parameters for [daytona.GitService.Push].
type GitPush struct { Username *string // Username for HTTPS authentication Password *string // Password or token for HTTPS authentication}type PipInstall
Section titled “type PipInstall”PipInstall holds optional parameters for [daytona.Image.PipInstall].
type PipInstall struct { FindLinks []string // URLs to search for packages IndexURL string // Base URL of the Python Package Index ExtraIndexURLs []string // Extra index URLs for package lookup Pre bool // Allow pre-release and development versions ExtraOptions string // Additional pip command-line options}type PtySession
Section titled “type PtySession”PtySession holds optional parameters for [daytona.ProcessService.CreatePtySession].
type PtySession struct { PtySize *types.PtySize // Terminal dimensions (rows and columns) Env map[string]string // Environment variables for the PTY session}type RunCode
Section titled “type RunCode”RunCode holds optional parameters for [daytona.CodeInterpreterService.RunCode].
type RunCode struct { ContextID string // Interpreter context ID for persistent state Env map[string]string // Environment variables for code execution Timeout *time.Duration // Execution timeout}type SetFilePermissions
Section titled “type SetFilePermissions”SetFilePermissions holds optional parameters for [daytona.FileSystemService.SetFilePermissions].
type SetFilePermissions struct { Mode *string // Unix file permissions (e.g., "0644") Owner *string // File owner username Group *string // File group name}