0.5.4

Execute Shell Commands

Run shell commands directly in your sandbox environment.

sandbox.execute( command: str, timeout: int = 10000 ) -> ExecuteResult

Parameters

commandstringrequired

Shell command to execute (e.g., ls -la, python -V).

timeoutint

Timeout in milliseconds. Defaults to 10000 (10000ms).

Returns

stdoutstr

Standard output from the command.

stderrstr

Standard error from the command.

returncodeint

Exit code from the command (0 = success, non-zero = error).

commandstr

The original command that was executed.

Examples

Basic Example

from concave import Sandbox sbx = Sandbox.create() result = sbx.execute("uname -a") print(f"Output: {result.stdout}") print(f"Exit code: {result.returncode}") sbx.delete()

File Operations

from concave import Sandbox sbx = Sandbox.create() sbx.execute("echo 'Hello World' > /tmp/test.txt") result = sbx.execute("cat /tmp/test.txt") print(result.stdout) # Hello World sbx.delete()

With Timeout

from concave import Sandbox, SandboxTimeoutError sbx = Sandbox.create() try: result = sbx.execute("sleep 5", timeout=2000) except SandboxTimeoutError as e: print(f"Timed out: {e}") finally: sbx.delete()

Exceptions

SandboxValidationErrorException

Raised when the command is empty or invalid.

SandboxNotFoundErrorException

Raised when the sandbox no longer exists.

SandboxTimeoutErrorException

Raised when command execution exceeds the timeout duration.

SandboxConnectionErrorException

Raised when unable to connect to the sandbox service.

Error Handling

from concave import ( Sandbox, SandboxValidationError, SandboxTimeoutError ) sbx = Sandbox.create() try: result = sbx.execute("invalid command") print(result.stdout) except SandboxValidationError as e: print(f"Invalid command: {e}") except SandboxTimeoutError as e: print(f"Command timed out: {e}") finally: sbx.delete()