# Execute Command

`POST /workspaces/:workspace/sandboxes/:sandbox_id/exec`

Run a command in a sandbox and return its result

**Required Scopes:** `SANDBOX_WRITE`

## URL Parameters

```typescript
interface URLParameters {
  /** The human-readable ID of the workspace */
  workspace: string; // Example: "my-company"
  /** The ID of the sandbox */
  sandbox_id: string; // Example: "sb-1234567890abcdef"
}
```

## Body Parameters

```typescript
interface BodyParameters {
  /** Command to execute in the sandbox */
  command: string;
  /** Runtime environment for command execution (default: `BASH`) */
  runtime?: "BASH" | "JAVASCRIPT" | "TYPESCRIPT" | "PYTHON";
}
```

## Response Body

```typescript
interface ResponseBody {
  /** Command to execute in the sandbox */
  command?: string;
  /** Runtime environment for command execution (default: `BASH`) */
  runtime?: "BASH" | "JAVASCRIPT" | "TYPESCRIPT" | "PYTHON";
  /** Command exit code */
  exit_code?: number;
  /** Everything the command wrote to standard output */
  stdout?: string;
  /** Everything the command wrote to standard error */
  stderr?: string;
}
```

## Request Example

```bash
curl -X POST "https://api.buddy.works/workspaces/:workspace/sandboxes/:sandbox_id/exec" \
  -H "Authorization: Bearer <YOUR-TOKEN>" \
  -H "Content-Type: application/json" \
  -d '{
  "command": "npm test",
  "runtime": "BASH"
}'
```

## Response Example

**Status:** `200 OK`

```json
{
  "command": "npm test",
  "runtime": "BASH",
  "exit_code": 0,
  "stdout": "All tests passed\n",
  "stderr": ""
}
```

---
Original source: https://buddy.works/docs/api/sandboxes/exec