Appearance
Class: Command
📖 Related Tutorial
- Command Execution Guide - Learn how to execute commands in sessions
Overview
The Command module provides methods for executing shell commands within a session in the AGB cloud environment. It supports command execution with configurable timeouts.
Command module for executing shell commands in the session.
Hierarchy
BaseService↳
Command
Table of contents
Properties
Methods
Properties
typescript
exec: (`command`: `string`, `timeoutMs`: `number`, `cwd?`: `string`, `envs?`: `Record`<`string`, `string`>) => `Promise`<``CommandResult``>
run: (`command`: `string`, `timeoutMs`: `number`, `cwd?`: `string`, `envs?`: `Record`<`string`, `string`>) => `Promise`<``CommandResult``>Type declaration
▸ (command, timeoutMs?, cwd?, envs?): Promise<CommandResult>
Execute a shell command in the session.
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
command | string | undefined | The command string to execute |
timeoutMs | number | 1000 | Timeout in milliseconds (default 1000) |
cwd? | string | undefined | Optional working directory |
envs? | Record<string, string> | undefined | Optional environment variables (key-value pairs) |
Returns
Promise<CommandResult>
Promise resolving to CommandResult with stdout, stderr, exitCode
Type declaration
▸ (command, timeoutMs?, cwd?, envs?): Promise<CommandResult>
Parameters
| Name | Type | Default value |
|---|---|---|
command | string | undefined |
timeoutMs | number | 1000 |
cwd? | string | undefined |
envs? | Record<string, string> | undefined |
Returns
Promise<CommandResult>
session
• Protected session: SessionLike
Inherited from
BaseService.session
Methods
callMcpTool
▸ callMcpTool(name, args, readTimeout?, connectTimeout?): Promise<OperationResult>
Parameters
| Name | Type |
|---|---|
name | string |
args | Record<string, unknown> |
readTimeout? | number |
connectTimeout? | number |
Returns
Promise<OperationResult>
Inherited from
BaseService.callMcpTool
execute
▸ execute(command, timeoutMs?, cwd?, envs?): Promise<CommandResult>
Execute a shell command in the session.
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
command | string | undefined | The command string to execute |
timeoutMs | number | 1000 | Timeout in milliseconds (default 1000) |
cwd? | string | undefined | Optional working directory |
envs? | Record<string, string> | undefined | Optional environment variables (key-value pairs) |
Returns
Promise<CommandResult>
Promise resolving to CommandResult with stdout, stderr, exitCode
handleError
▸ handleError(e): unknown
Parameters
| Name | Type |
|---|---|
e | unknown |
Returns
unknown
Inherited from
BaseService.handleError
toJSON
▸ toJSON(): Record<string, unknown>
Returns
Record<string, unknown>
Inherited from
BaseService.toJSON
Best Practices
- Always specify appropriate timeout values based on expected command duration
- Handle command execution errors gracefully
- Use absolute paths when referencing files in commands, or use the
cwdparameter - Use the
cwdparameter to set working directory instead ofcdcommands - Use the
envsparameter to set environment variables instead ofexportcommands - Check
exit_codefor more precise error handling (0 means success) - Use
stdoutandstderrseparately for better output parsing - Be aware that commands run with session user permissions
- Clean up temporary files created by commands