# Pty (/docs/java-sdk/pty)

## PtyCreateOptions [#ptycreateoptions]

Options used when creating a PTY session in a Sandbox.

### Constructors [#constructors]

#### new PtyCreateOptions() [#new-ptycreateoptions]
```java
public PtyCreateOptions()
```

Creates PTY options with default dimensions (`120x30`).

#### new PtyCreateOptions() [#new-ptycreateoptions-1]
```java
public PtyCreateOptions(String id, int cols, int rows, Consumer<byte[]> onData)
```

Creates PTY options with explicit values.

**Parameters**:

- `id` _String_ - custom PTY session identifier; if `null`, the server generates one
- `cols` _int_ - terminal width in columns
- `rows` _int_ - terminal height in rows
- `onData` _Consumer\<byte[]\>_ - callback invoked for each PTY output chunk

### Methods [#methods]

#### getId() [#getid]
```java
public String getId()
```

Returns the PTY session identifier to request.

**Returns**:

- `String` - requested PTY session identifier, or `null` to auto-generate

#### setId() [#setid]
```java
public PtyCreateOptions setId(String id)
```

Sets the PTY session identifier.

**Parameters**:

- `id` _String_ - PTY session identifier

**Returns**:

- `PtyCreateOptions` - this options instance

#### getCols() [#getcols]
```java
public int getCols()
```

Returns terminal width in columns.

**Returns**:

- `int` - terminal width

#### setCols() [#setcols]
```java
public PtyCreateOptions setCols(int cols)
```

Sets terminal width in columns.

**Parameters**:

- `cols` _int_ - terminal width

**Returns**:

- `PtyCreateOptions` - this options instance

#### getRows() [#getrows]
```java
public int getRows()
```

Returns terminal height in rows.

**Returns**:

- `int` - terminal height

#### setRows() [#setrows]
```java
public PtyCreateOptions setRows(int rows)
```

Sets terminal height in rows.

**Parameters**:

- `rows` _int_ - terminal height

**Returns**:

- `PtyCreateOptions` - this options instance

#### getOnData() [#getondata]
```java
public Consumer<byte[]> getOnData()
```

Returns callback used for streaming PTY output.

**Returns**:

- `Consumer\<byte[]\>` - PTY output callback, or `null` when not configured

#### setOnData() [#setondata]
```java
public PtyCreateOptions setOnData(Consumer<byte[]> onData)
```

Sets callback invoked for each PTY output chunk.

**Parameters**:

- `onData` _Consumer\<byte[]\>_ - callback receiving raw PTY bytes

**Returns**:

- `PtyCreateOptions` - this options instance

#### getCwd() [#getcwd]
```java
public String getCwd()
```

Returns the working directory for the PTY session.

**Returns**:

- `String` - working directory, or `null` to use the sandbox default

#### setCwd() [#setcwd]
```java
public PtyCreateOptions setCwd(String cwd)
```

Sets the working directory for the PTY session.

**Parameters**:

- `cwd` _String_ - working directory

**Returns**:

- `PtyCreateOptions` - this options instance

#### getEnvs() [#getenvs]
```java
public Map<String, String> getEnvs()
```

Returns environment variables for the PTY session.

**Returns**:

- `Map\<String, String\>` - environment variables, or `null` when none configured

#### setEnvs() [#setenvs]
```java
public PtyCreateOptions setEnvs(Map<String, String> envs)
```

Sets environment variables for the PTY session.

**Parameters**:

- `envs` _Map\<String, String\>_ - environment variables

**Returns**:

- `PtyCreateOptions` - this options instance

## PtyResult [#ptyresult]

Final outcome of a PTY session.

Contains exit status and an optional error/exit reason reported by the PTY backend.

### Constructors [#constructors-1]

#### new PtyResult() [#new-ptyresult]
```java
public PtyResult(int exitCode, String error)
```

Creates a PTY result object.

**Parameters**:

- `exitCode` _int_ - exit code returned by the PTY process; negative values indicate no exit code
- `error` _String_ - optional error or exit reason

### Methods [#methods-1]

#### getExitCode() [#getexitcode]
```java
public int getExitCode()
```

Returns the process exit code.

**Returns**:

- `int` - PTY process exit code

#### getError() [#geterror]
```java
public String getError()
```

Returns the PTY error or exit reason when available.

**Returns**:

- `String` - error message, or `null` when the session ended successfully
