LocalEnvironment

class LocalEnvironment @JvmOverloads constructor(workingDir: String? = null, envVars: Map<String, String> = emptyMap(), inheritedEnvVarAllowlist: Set<String>? = null) : Environment

An Environment that runs commands in local /bin/sh subprocesses and reads and writes files in one workspace directory shared by every caller, so it ignores the per-call Context.

Without a workingDir, initialize creates a temporary directory that close deletes; a given directory is created if missing and never deleted. There is no sandboxing: commands run with the host's privileges and environment variables (filtered by inheritedEnvVarAllowlist, with envVars on top), and on timeout or cancellation they get SIGTERM, then SIGKILL.

Parameters

workingDir

Absolute path to the workspace directory. If null or empty, a temporary directory is created during initialize.

envVars

Extra environment variables for every command, applied after the allowlist.

inheritedEnvVarAllowlist

Names of the host's environment variables commands may inherit; null inherits all of them. PATH is always inherited, so commands find the host's programs.

Constructors

Link copied to clipboard
constructor(workingDir: String? = null, envVars: Map<String, String> = emptyMap(), inheritedEnvVarAllowlist: Set<String>? = null)

Types

Link copied to clipboard
class Builder

Fluent builder for LocalEnvironment, provided primarily for Java callers. Any property left unset falls back to the same default as the constructor.

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
open override fun close()

Releases resources held by the environment.

Link copied to clipboard
open suspend override fun execute(context: Context, command: String, timeout: Duration? = null): Result<ExecutionResult>

Executes a shell command in the calling session's workspace.

Link copied to clipboard
open suspend override fun initialize()

Prepares resources shared by all sessions, such as a local directory or a client connection.

Link copied to clipboard
open suspend override fun readFile(context: Context, path: String): Result<ByteArray>

Reads a file from the calling session's workspace.

Link copied to clipboard
open suspend override fun writeFile(context: Context, path: String, content: ByteArray): Result<Unit>

Writes a file in the calling session's workspace, creating missing parent directories.