---
title: "Run code on the box"
method: POST
path: "/boxes/{boxId}/run-code"
tags: ["Run Code"]
---

# Run code on the box

`POST /boxes/{boxId}/run-code`

Executes code inside the specified box. Supports multiple languages (bash, Python, TypeScript) and allows you to configure environment variables, arguments, working directory, and timeouts.

## Path parameters

- `boxId` string, required

## Request body

- RunCode — Request parameters for running code in various languages
  - `code` string, required — The code to run
  - `language` 'bash' | 'python' | 'typescript' — The language of the code.
  - `envs` object — The environment variables to run the code
  - `argv` string[] — The arguments to run the code. For example, if you want to run "python index.py --help", you should pass ["--help"] as arguments.
  - `workingDir` string — The working directory of the code. It not provided, the code will be run in the `box.config.workingDir` directory.
  - `timeout` string — The timeout of the code execution. If the code execution times out, the exit code will be 124. Supported time units: ms (milliseconds), s (seconds), m (minutes), h (hours) Example formats: "500ms", "30s", "5m", "1h" Default: 30s

## Response `200`

- RunCodeResult — Result of code execution
  - `exitCode` number, required — The exit code of the code
  - `stdout` string, required — The stdout of the code
  - `stderr` string, required — The stderr of the code

---

[API](https://skmtc.dev/babelcloud/apis/gbox-open-api.md) · [All operations](https://skmtc.dev/babelcloud/apis/gbox-open-api/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/babelcloud/gbox-open-api/revisions/d655577fa915/schema)
