### Manual Installation with Conda and Poetry
Source: https://github.com/bytedance/sandboxfusion/blob/main/README.md
Installs the sandbox service manually using conda for environment management and poetry for dependency installation. Assumes conda and poetry are already installed.
```bash
conda create -n sandbox -y python=3.12
conda activate sandbox
poetry install
# to build the real docs, run `cd docs && npm ci && npm run build`
mkdir -p docs/build
make run-online
```
--------------------------------
### Start Local Development Server
Source: https://github.com/bytedance/sandboxfusion/blob/main/docs/README.md
Starts a local development server for live preview and development. Changes are reflected without server restart.
```bash
yarn start
```
--------------------------------
### Install Python Runtime
Source: https://github.com/bytedance/sandboxfusion/blob/main/README.md
Installs the Python runtime environment by executing the provided shell script. Navigate to the correct directory before running the script.
```bash
cd runtime/python
bash install-python-runtime.sh
```
--------------------------------
### Install Project Dependencies
Source: https://github.com/bytedance/sandboxfusion/blob/main/docs/README.md
Installs all necessary project dependencies using Yarn.
```bash
yarn
```
--------------------------------
### Example Response (JSON)
Source: https://github.com/bytedance/sandboxfusion/blob/main/docs/docs/api/get-metrics-function-get-metrics-function-post.api.mdx
This snippet shows an example of a successful response from the API, detailing the structure of the returned metrics.
```json
{
"detail": [
{
"loc": [
"string",
0
],
"msg": "string",
"type": "string"
}
]
}
```
--------------------------------
### JSON Response Example
Source: https://github.com/bytedance/sandboxfusion/blob/main/docs/docs/api/get-metrics-function-get-metrics-function-post.api.mdx
An example of a successful JSON response from the Get Metrics Function API.
```json
{
"function": "string"
}
```
--------------------------------
### Install Sandbox Fusion SDK
Source: https://github.com/bytedance/sandboxfusion/blob/main/docs/docs/docs/how-to/python-sdk.md
Install the Sandbox Fusion Python SDK using pip. Requires Python version 3.8 or higher.
```bash
pip install sandbox-fusion
```
--------------------------------
### Running SQL Queries
Source: https://github.com/bytedance/sandboxfusion/blob/main/docs/docs/docs/how-to/run-code/jupyter-mode.mdx
Example of executing a SQL query. This assumes a database connection is established and configured.
```sql
SELECT *
FROM your_table_name
WHERE condition = 'some_value'
LIMIT 10;
```
--------------------------------
### Get Prompt by ID
Source: https://github.com/bytedance/sandboxfusion/blob/main/docs/docs/api/get-prompt-get-prompt-by-id-post.api.mdx
Fetches a prompt using its ID. This endpoint allows for specifying locale, few-shot examples, and compilation timeouts.
```APIDOC
## POST /get-prompt/{id}
### Description
Retrieves a specific prompt by its unique identifier. This endpoint allows for specifying locale, few-shot examples, and compilation timeouts.
### Method
POST
### Endpoint
/get-prompt/{id}
### Parameters
#### Path Parameters
- **id** (string) - Required - The unique identifier of the prompt.
#### Request Body
- **locale** (string) - Optional - Specifies the locale for the prompt.
- **is_fewshot** (boolean) - Optional - Indicates whether to include few-shot examples.
- **compile_timeout** (integer) - Optional - Sets the timeout for compilation in seconds.
```
--------------------------------
### Data Visualization with Matplotlib
Source: https://github.com/bytedance/sandboxfusion/blob/main/docs/docs/docs/how-to/run-code/jupyter-mode.mdx
Shows how to create a basic plot using Matplotlib. This requires the Matplotlib library to be installed.
```python
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 10, 100)
y = np.sin(x)
plt.figure(figsize=(8, 6))
plt.plot(x, y, label='sin(x)')
plt.title('Sine Wave')
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.legend()
plt.grid(True)
plt.show()
```
--------------------------------
### Root GET
Source: https://github.com/bytedance/sandboxfusion/blob/main/docs/docs/api/root-get.api.mdx
Retrieves a successful response from the root endpoint.
```APIDOC
## GET /
### Description
Retrieves a successful response from the root endpoint.
### Method
GET
### Endpoint
/
### Response
#### Success Response (200)
- **response** (string) - Successful Response
```
--------------------------------
### Markdown Cell Example
Source: https://github.com/bytedance/sandboxfusion/blob/main/docs/docs/docs/how-to/run-code/jupyter-mode.mdx
Shows how to use Markdown for documentation within a Jupyter notebook. This is not executable code.
```markdown
# Markdown Example
This is a **bold** text and this is an *italic* text.
- Item 1
- Item 2
[Link to SandboxFusion](https://sandboxfusion.com)
```
--------------------------------
### Basic Python Execution in Jupyter Mode
Source: https://github.com/bytedance/sandboxfusion/blob/main/docs/docs/docs/how-to/run-code/jupyter-mode.mdx
Demonstrates a simple Python script execution. Ensure you have Python installed and configured in your environment.
```python
print("Hello, Jupyter!")
a = 5
b = 10
print(f"The sum of {a} and {b} is {a + b}")
```
--------------------------------
### Get Prompts
Source: https://github.com/bytedance/sandboxfusion/blob/main/docs/docs/api/get-prompt-get-prompts-post.api.mdx
Retrieves a list of prompts. Supports filtering and pagination.
```APIDOC
## POST /get-prompts
### Description
Retrieves a list of prompts based on provided filters and pagination.
### Method
POST
### Endpoint
/get-prompts
### Parameters
#### Query Parameters
- **limit** (integer) - Optional - The maximum number of prompts to return.
- **offset** (integer) - Optional - The number of prompts to skip before returning results.
#### Request Body
- **prompt_ids** (string[]) - Optional - A list of prompt IDs to filter by.
- **tags** (string[]) - Optional - A list of tags to filter prompts by.
- **search_query** (string) - Optional - A search string to filter prompts.
### Response
#### Success Response (200)
- **prompts** (object[]) - A list of prompt objects.
- **id** (string) - The unique identifier for the prompt.
- **name** (string) - The name of the prompt.
- **description** (string) - A brief description of the prompt.
- **tags** (string[]) - Tags associated with the prompt.
- **created_at** (string) - The timestamp when the prompt was created.
- **updated_at** (string) - The timestamp when the prompt was last updated.
#### Response Example (200)
```json
{
"prompts": [
{
"id": "prompt-123",
"name": "Example Prompt",
"description": "This is an example prompt.",
"tags": ["example", "api"],
"created_at": "2023-10-27T10:00:00Z",
"updated_at": "2023-10-27T10:00:00Z"
}
]
}
```
#### Error Response (422)
- **detail** (object[]) - An array of validation error details.
- **loc** (object[]) - The location of the validation error.
- **type** (string) - The type of location (e.g., 'body', 'query').
- **msg** (string) - The error message.
- **input** (any) - The input value that caused the error.
- **ctx** (object) - Contextual information about the error.
- **msg** (string) - The error message.
- **type** (string) - The error type.
#### Response Example (422)
```json
{
"detail": [
{
"loc": [
{
"type": "query",
"name": "limit"
}
],
"msg": "value is not a valid integer",
"type": "type_error.integer"
}
]
}
```
```
--------------------------------
### Run SandboxFusion Docker Image
Source: https://github.com/bytedance/sandboxfusion/blob/main/docs/docs/docs/get-started.mdx
Use this command to run the SandboxFusion Docker image locally. Ensure you have Docker installed.
```bash
docker run -it -p 8080:8080 { constants.image }
```
--------------------------------
### Data Manipulation with Pandas
Source: https://github.com/bytedance/sandboxfusion/blob/main/docs/docs/docs/how-to/run-code/jupyter-mode.mdx
Illustrates basic data manipulation using the Pandas library. Make sure Pandas is installed.
```python
import pandas as pd
data = {'col1': [1, 2, 3, 4], 'col2': ['A', 'B', 'C', 'D']}
df = pd.DataFrame(data)
print(df.head())
print("\nDataFrame Info:")
df.info()
```
--------------------------------
### Get Prompts
Source: https://github.com/bytedance/sandboxfusion/blob/main/docs/docs/api/get-prompt-get-prompts-post.api.mdx
Retrieves a list of prompts. Supports filtering by dataset type and language, and sorting by creation time.
```APIDOC
## GET /prompts
### Description
Retrieves a list of prompts. Supports filtering by dataset type and language, and sorting by creation time.
### Method
GET
### Endpoint
/prompts
### Parameters
#### Query Parameters
- **dataset_type** (object) - Optional - The dataset class used to process, only works when the dataset id is not registered.
- **language** (object) - Optional - Specifies the programming language for the prompts. Possible values include: `python`, `cpp`, `nodejs`, `go`, `go_test`, `java`, `php`, `csharp`, `bash`, `typescript`, `sql`, `rust`, `cuda`, `lua`, `R`, `perl`, `D_ut`, `ruby`, `scala`, `julia`, `pytest`, `junit`, `kotlin_script`, `jest`, `verilog`, `python_gpu`, `lean`, `swift`, `racket`.
### Response
#### Success Response (200)
- **prompts** (array) - A list of prompt objects.
- **id** (string) - The unique identifier of the prompt.
- **content** (string) - The content of the prompt.
- **created_at** (string) - The timestamp when the prompt was created.
- **updated_at** (string) - The timestamp when the prompt was last updated.
#### Response Example
```json
{
"prompts": [
{
"id": "prompt-123",
"content": "Write a Python function to calculate the factorial of a number.",
"created_at": "2023-10-27T10:00:00Z",
"updated_at": "2023-10-27T10:00:00Z"
}
]
}
```
```
--------------------------------
### Get Prompt
Source: https://github.com/bytedance/sandboxfusion/blob/main/docs/docs/api/get-prompt-get-prompts-post.api.mdx
Fetches prompts for a given dataset. The request body must include the dataset identifier and configuration details.
```APIDOC
## POST /get_prompts
### Description
Get prompts of a dataset
### Method
POST
### Endpoint
/get_prompts
### Parameters
#### Request Body
- **dataset** (string) - Required - The identifier of the dataset.
- **config** (object) - Required - Configuration object for the prompt retrieval.
- **model** (string) - Required - The model to use for prompt generation.
- **temperature** (number) - Optional - The temperature for sampling.
- **max_tokens** (number) - Optional - The maximum number of tokens to generate.
- **top_p** (number) - Optional - The top-p sampling parameter.
- **stream** (boolean) - Optional - Whether to stream the response.
- **stop** (array) - Optional - Sequences where the API will stop generating further tokens.
- **prompt** (string) - Required - The prompt to use for generation.
### Request Example
```json
{
"dataset": "string",
"config": {
"model": "string",
"temperature": 0.7,
"max_tokens": 100,
"top_p": 0.9,
"stream": false,
"stop": [
"string"
],
"prompt": "string"
}
}
```
### Response
#### Success Response (200)
- **prompts** (array) - A list of prompts.
- **prompt** (string) - The content of the prompt.
- **config** (object) - The configuration used for the prompt.
- **model** (string) - The model used.
- **temperature** (number) - The temperature setting.
- **max_tokens** (number) - The maximum tokens setting.
- **top_p** (number) - The top-p setting.
- **stream** (boolean) - The stream setting.
- **stop** (array) - The stop sequences.
- **prompt** (string) - The prompt text.
#### Response Example
```json
{
"prompts": [
{
"prompt": "string",
"config": {
"model": "string",
"temperature": 0.7,
"max_tokens": 100,
"top_p": 0.9,
"stream": false,
"stop": [
"string"
],
"prompt": "string"
}
}
]
}
```
```
--------------------------------
### Get MBPP Prompts
Source: https://github.com/bytedance/sandboxfusion/blob/main/docs/docs/docs/get-started.mdx
Use this cURL command to fetch prompts for the MBPP dataset. Ensure the correct host and content type are specified.
```bash
curl '${ constants.host }/get_prompts' \
-H 'Content-Type: application/json' \
--data-raw '{"dataset":"mbpp","config":{}}'
```
--------------------------------
### POST /get-prompts
Source: https://github.com/bytedance/sandboxfusion/blob/main/docs/docs/api/get-prompt-get-prompts-post.api.mdx
Retrieves a list of prompts based on the provided criteria. Supports filtering by locale and few-shot examples, and setting a compilation timeout.
```APIDOC
## POST /get-prompts
### Description
Retrieves a list of prompts. This endpoint allows for filtering based on locale and whether few-shot examples are used, and also accepts a compilation timeout.
### Method
POST
### Endpoint
/get-prompts
### Parameters
#### Request Body
- **locale** (string) - Optional - Specifies the locale for filtering prompts.
- **is_fewshot** (boolean) - Optional - Filters prompts based on whether they use few-shot examples.
- **compile_timeout** (integer) - Optional - Sets a timeout for prompt compilation in seconds.
```
--------------------------------
### Get Prompts
Source: https://github.com/bytedance/sandboxfusion/blob/main/docs/docs/api/get-prompt-get-prompts-post.api.mdx
Retrieves a list of prompts based on specified criteria. This endpoint is useful for fetching prompt configurations and details.
```APIDOC
## POST /get-prompts
### Description
Retrieves a list of prompts. This endpoint allows for filtering and pagination of prompt data.
### Method
POST
### Endpoint
/get-prompts
### Request Body
- **prompt_ids** (array[string]) - Optional - A list of prompt IDs to filter the results.
- **prompt_names** (array[string]) - Optional - A list of prompt names to filter the results.
- **limit** (number) - Optional - The maximum number of prompts to return.
- **offset** (number) - Optional - The number of prompts to skip before returning results.
- **run_timeout** (object) - Optional - Configuration for run timeout.
- **MOD1** (number) - Specifies the timeout duration in minutes.
- **custom_extract_logic** (object) - Optional - Configuration for custom extraction logic.
- **MOD1** (string) - Specifies the custom extraction logic script.
- **provided_data** (object) - Optional - Data to be provided for prompt execution.
### Response
#### Success Response (200)
- **prompts** (array[object]) - A list of prompt objects.
- **id** (string) - The unique identifier of the prompt.
- **name** (string) - The name of the prompt.
- **description** (string) - A description of the prompt.
- **created_at** (string) - The timestamp when the prompt was created.
- **updated_at** (string) - The timestamp when the prompt was last updated.
- **created_by** (string) - The user who created the prompt.
- **updated_by** (string) - The user who last updated the prompt.
- **tags** (array[string]) - Tags associated with the prompt.
- **prompt_content** (string) - The actual content of the prompt.
- **is_public** (boolean) - Indicates if the prompt is public.
- **is_favorite** (boolean) - Indicates if the prompt is a favorite.
- **run_count** (number) - The number of times the prompt has been run.
- **favorite_count** (number) - The number of users who favorited the prompt.
- **created_by_user_id** (string) - The ID of the user who created the prompt.
- **updated_by_user_id** (string) - The ID of the user who last updated the prompt.
- **run_timeout** (number) - The run timeout configuration for the prompt.
- **custom_extract_logic** (string) - The custom extraction logic for the prompt.
- **provided_data** (object) - The provided data for the prompt.
#### Response Example
```json
{
"prompts": [
{
"id": "prompt-123",
"name": "Summarize Text",
"description": "Summarizes a given piece of text.",
"created_at": "2023-10-27T10:00:00Z",
"updated_at": "2023-10-27T10:00:00Z",
"created_by": "user1",
"updated_by": "user1",
"tags": ["summarization", "nlp"],
"prompt_content": "Please summarize the following text: {{text}}",
"is_public": true,
"is_favorite": false,
"run_count": 150,
"favorite_count": 25,
"created_by_user_id": "user-abc",
"updated_by_user_id": "user-abc",
"run_timeout": 5,
"custom_extract_logic": "",
"provided_data": {}
}
]
}
```
```
--------------------------------
### Finding PyTorch Dependencies
Source: https://github.com/bytedance/sandboxfusion/blob/main/sandbox/tests/runners/samples/cuda/CMakeLists.txt
Dynamically determines the PyTorch installation path and adds it to the CMake prefix path. It then finds the PyTorch package and includes its directories.
```cmake
# PyTorch deps
execute_process(COMMAND python3 -c "import torch; print(torch.utils.cmake_prefix_path)"
OUTPUT_VARIABLE TORCH_PREFIX_PATH
OUTPUT_STRIP_TRAILING_WHITESPACE)
list(APPEND CMAKE_PREFIX_PATH ${TORCH_PREFIX_PATH})
find_package(Torch REQUIRED)
include_directories(${TORCH_INCLUDE_DIRS})
```
--------------------------------
### MBPP Dataset Selector Configuration
Source: https://github.com/bytedance/sandboxfusion/blob/main/docs/docs/docs/how-to/use-dataset/mbpp.mdx
Configures the DatasetSelector component for the MBPP dataset. Includes options for few-shot examples and execution timeout.
```javascript
import DatasetSelector from '@site/src/components/DatasetSelector';
import { docWithType } from '@site/src/components/DatasetSelector/docGenerator';
```
--------------------------------
### Get Prompt by ID
Source: https://github.com/bytedance/sandboxfusion/blob/main/sandbox/pages/oj.html
Retrieves a specific prompt using the selected dataset, ID, and configuration, then displays it in the prompt textarea.
```javascript
async function getPrompt() {
const dataset = document.getElementById('dataset').value;
const id = document.getElementById('id').value;
const config = JSON.parse(document.getElementById('config').value);
const response = await axios.post(rewriteEndpoint('/get_prompt_by_id'), {
dataset,
id,
config
});
const prompt = response.data;
document.getElementById('prompt').textContent = prompt.prompt;
}
```
--------------------------------
### Get Prompts
Source: https://github.com/bytedance/sandboxfusion/blob/main/docs/docs/api/get-prompt-get-prompts-post.api.mdx
Fetches a list of prompts. This endpoint supports filtering by prompt ID and returns an array of prompt objects.
```APIDOC
## GET /prompts
### Description
Retrieves a list of prompts. The response includes an array of prompt objects, each containing an ID, the prompt text, and optional labels.
### Method
GET
### Endpoint
/prompts
### Parameters
#### Query Parameters
- **id** (integer) - Optional - Filters prompts by their unique identifier.
### Response
#### Success Response (200)
- **id** (integer) - Required - The unique identifier of the prompt.
- **prompt** (string) - Required - The text content of the prompt.
- **labels** (object) - Optional - A key-value map of labels associated with the prompt.
### Response Example
```json
[
{
"id": 0,
"prompt": "string",
"labels": {}
}
]
```
```
--------------------------------
### Compile and Run Java Code
Source: https://github.com/bytedance/sandboxfusion/blob/main/docs/docs/docs/reference/execution-detail/java.md
Use this command for standard Java execution. Ensure the class name is 'Main' and include all necessary JAR files in the classpath.
```bash
javac -cp .:javatuples-1.2.jar: Main.java
java -cp .:javatuples-1.2.jar: -ea Main
```
--------------------------------
### Get Metrics POST Request
Source: https://github.com/bytedance/sandboxfusion/blob/main/docs/docs/api/get-metrics-get-metrics-post.api.mdx
This snippet details the structure of a POST request to the Get Metrics API, focusing on the `provided_data` field.
```APIDOC
## POST /get-metrics
### Description
Retrieves metrics based on the provided data.
### Method
POST
### Endpoint
/get-metrics
### Parameters
#### Request Body
- **provided_data** (object) - Required - An object containing the data for which metrics are to be retrieved. This can be an array of strings or an array of integers.
### Request Example
```json
{
"provided_data": [
"example_string_1",
"example_string_2"
]
}
```
OR
```json
{
"provided_data": [
123,
456
]
}
```
### Response
#### Success Response (200)
- **metrics** (object) - Description of the metrics returned (details not provided in source).
#### Response Example
```json
{
"metrics": {
"example_metric_1": "value1",
"example_metric_2": 100
}
}
```
```
--------------------------------
### Create C# Console Project
Source: https://github.com/bytedance/sandboxfusion/blob/main/docs/docs/docs/reference/execution-detail/csharp.md
Initializes a new C# console application in a temporary directory. This command is run before writing any input code.
```bash
dotnet new console -o
```
--------------------------------
### Get Metrics Function Parameters
Source: https://github.com/bytedance/sandboxfusion/blob/main/docs/docs/api/get-metrics-function-get-metrics-function-post.api.mdx
This snippet details the parameters accepted by the Get Metrics Function API, including locale, is_fewshot, and compile_timeout.
```APIDOC
## POST /get-metrics-function
### Description
Retrieves metrics based on the provided parameters.
### Method
POST
### Endpoint
/get-metrics-function
### Parameters
#### Request Body
- **locale** (object) - anyOf: string
- **is_fewshot** (object) - anyOf: boolean
- **compile_timeout** (object) - anyOf: number
```
--------------------------------
### MiniF2F Dataset Configuration
Source: https://github.com/bytedance/sandboxfusion/blob/main/docs/docs/docs/how-to/use-dataset/minif2f.mdx
Configure the MiniF2F dataset with custom prompt templates, locale settings, and run timeouts. The prompt template allows dynamic filling of placeholders with sample data.
```javascript
import DatasetSelector from '@site/src/components/DatasetSelector';
import { docWithType } from '@site/src/components/DatasetSelector/docGenerator';
```
--------------------------------
### Build Docker Image Locally
Source: https://github.com/bytedance/sandboxfusion/blob/main/README.md
Builds the base Docker image for the code sandbox. Ensure to update the Dockerfile.server with the correct base image before building the server image.
```bash
docker build -f ./scripts/Dockerfile.base -t code_sandbox:base .
# change the base image in Dockerfile.server
sed -i '1s/.*/FROM code_sandbox:base/' ./scripts/Dockerfile.server
docker build -f ./scripts/Dockerfile.server -t code_sandbox:server .
docker run -d --rm -p 8080:8080 code_sandbox:server make run-online
```
--------------------------------
### Get Metrics
Source: https://github.com/bytedance/sandboxfusion/blob/main/docs/docs/api/get-metrics-get-metrics-post.api.mdx
Retrieves metrics for a given dataset. This endpoint is partially supported.
```APIDOC
## POST /get_metrics
### Description
Get the metrics given all problem results in a dataset (partially supported)
### Method
POST
### Endpoint
/get_metrics
### Parameters
#### Request Body
- **dataset** (string) - Required - The dataset for which to retrieve metrics.
- **config** (object) - Optional - Configuration details for the metric retrieval.
```
--------------------------------
### Run SandboxFusion Docker Image (China Mirror)
Source: https://github.com/bytedance/sandboxfusion/blob/main/docs/docs/docs/get-started.mdx
Use this command to run the SandboxFusion Docker image locally using a mirror for users in mainland China. Ensure you have Docker installed.
```bash
docker run -it -p 8080:8080 { constants.cnImage }
```
--------------------------------
### Get Prompts
Source: https://github.com/bytedance/sandboxfusion/blob/main/docs/docs/api/get-prompt-get-prompts-post.api.mdx
Retrieves a list of prompts. Supports filtering by prompt ID and pagination.
```APIDOC
## GET /prompts
### Description
Retrieves a list of prompts. Supports filtering by prompt ID and pagination.
### Method
GET
### Endpoint
/prompts
### Parameters
#### Query Parameters
- **prompt_ids** (array[string]) - Optional - A list of prompt IDs to filter by.
- **limit** (integer) - Optional - The maximum number of prompts to return.
- **offset** (integer) - Optional - The number of prompts to skip before returning results.
### Response
#### Success Response (200)
- **prompts** (array[object]) - A list of prompt objects.
- **id** (string) - The unique identifier for the prompt.
- **name** (string) - The name of the prompt.
- **description** (string) - A brief description of the prompt.
- **created_at** (string) - The timestamp when the prompt was created.
- **updated_at** (string) - The timestamp when the prompt was last updated.
#### Response Example
```json
{
"prompts": [
{
"id": "string",
"name": "string",
"description": "string",
"created_at": "string",
"updated_at": "string"
}
]
}
```
#### Error Response (422)
- **detail** (array[object]) - A list of validation errors.
- **loc** (array[string | integer]) - The location of the error in the request.
- **msg** (string) - The error message.
- **type** (string) - The type of error.
#### Response Example
```json
{
"detail": [
{
"loc": [
"string",
0
],
"msg": "string",
"type": "string"
}
]
}
```
```
--------------------------------
### Get Prompt by ID
Source: https://github.com/bytedance/sandboxfusion/blob/main/docs/docs/api/get-prompt-get-prompt-by-id-post.api.mdx
Fetches a prompt by its ID. The ID is provided in the request body.
```APIDOC
## POST /get-prompt
### Description
Retrieves a specific prompt using its unique identifier, which is sent in the request body.
### Method
POST
### Endpoint
/get-prompt
### Request Body
- **id** (string) - Required - The unique identifier of the prompt to retrieve.
### Request Example
{
"id": "prompt_12345"
}
### Response
#### Success Response (200)
- **prompt** (object) - Contains the details of the requested prompt.
- **property name** (object) - The name of the property within the prompt object.
- **anyOf** - Indicates that the property can be one of several types.
- **MOD1** (string) - Represents the prompt in string format.
- **MOD2** (integer) - Represents the prompt in integer format.
#### Response Example
{
"prompt": {
"property name": {
"anyOf": [
"string_value",
123
]
}
}
}
```
--------------------------------
### List Datasets
Source: https://github.com/bytedance/sandboxfusion/blob/main/docs/docs/api/list-datasets-list-datasets-get.api.mdx
Retrieves a list of all registered datasets. This is a GET request to the /list_datasets endpoint.
```APIDOC
## GET /list_datasets
### Description
List all registered datasets.
### Method
GET
### Endpoint
/list_datasets
### Response
#### Success Response (200)
- **Array of strings**: A list of dataset names.
#### Response Example
```json
[
"string"
]
```
```
--------------------------------
### Build Static Website Content
Source: https://github.com/bytedance/sandboxfusion/blob/main/docs/README.md
Generates the static content for the website, typically placed in the 'build' directory.
```bash
yarn build
```
--------------------------------
### Run All Unit Tests
Source: https://github.com/bytedance/sandboxfusion/blob/main/README.md
Executes all unit tests for the project. This command is used to ensure the codebase is functioning correctly.
```bash
make test
```
--------------------------------
### run_concurrent
Source: https://github.com/bytedance/sandboxfusion/blob/main/docs/docs/docs/how-to/python-sdk.md
Executes multiple operations concurrently. This example shows running `run_code` operations in parallel.
```APIDOC
## run_concurrent
### Description
Provides tools for concurrent requests, allowing batch execution of certain function operations. This example demonstrates running multiple `run_code` operations concurrently.
### Method
`run_concurrent(func, args: list, **kwargs)`
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
```python
from sandbox_fusion import set_sandbox_endpoint, run_concurrent, run_code, RunCodeRequest
set_sandbox_endpoint('https://faas-code-sandbox.bytedance.net/')
codes = [f'print({i})' for i in range(123, 456)]
results = run_concurrent(run_code, args=[[RunCodeRequest(code=c, language='python')] for c in codes])
```
### Response
#### Success Response
- The results of the concurrent operations.
```
--------------------------------
### Run Code
Source: https://github.com/bytedance/sandboxfusion/blob/main/docs/docs/api/run-code-run-code-post.api.mdx
Executes a given code snippet in a sandboxed environment and returns the output, including stdout and stderr.
```APIDOC
## POST /run-code
### Description
Executes a code snippet and returns its standard output and standard error.
### Method
POST
### Endpoint
/run-code
### Request Body
- **code** (string) - Required - The code snippet to execute.
- **language** (string) - Required - The programming language of the code snippet (e.g., "python", "javascript").
- **timeout** (integer) - Optional - The maximum execution time in seconds.
### Request Example
```json
{
"code": "print(\"Hello, World!\")",
"language": "python",
"timeout": 5
}
```
### Response
#### Success Response (200)
- **stdout** (string) - The standard output from the code execution.
- **stderr** (string) - The standard error from the code execution.
- **executor_pod_name** (string) - The name of the pod that executed the code.
#### Response Example
```json
{
"stdout": "Hello, World!\n",
"stderr": "",
"executor_pod_name": "executor-pod-12345"
}
```
```
--------------------------------
### Get Metrics
Source: https://github.com/bytedance/sandboxfusion/blob/main/docs/docs/api/get-metrics-get-metrics-post.api.mdx
Retrieves a list of available metrics. This endpoint allows for filtering and pagination of the results.
```APIDOC
## GET /metrics
### Description
Retrieves a list of available metrics. This endpoint allows for filtering and pagination of the results.
### Method
GET
### Endpoint
/metrics
### Parameters
#### Query Parameters
- **limit** (integer) - Optional - The maximum number of metrics to return.
- **offset** (integer) - Optional - The number of metrics to skip before returning results.
### Response
#### Success Response (200)
- **metrics** (array) - A list of metric objects.
- **metric_id** (string) - The unique identifier for the metric.
- **name** (string) - The name of the metric.
- **description** (string) - A brief description of the metric.
- **total** (integer) - The total number of metrics available.
#### Response Example
```json
{
"metrics": [
{
"metric_id": "cpu_usage",
"name": "CPU Usage",
"description": "Percentage of CPU utilized."
},
{
"metric_id": "memory_usage",
"name": "Memory Usage",
"description": "Percentage of memory utilized."
}
],
"total": 100
}
```
```
--------------------------------
### Get Prompt by ID
Source: https://github.com/bytedance/sandboxfusion/blob/main/docs/docs/api/get-prompt-get-prompt-by-id-post.api.mdx
Fetches a prompt using its ID. The ID is expected in the request body.
```APIDOC
## POST /get-prompt
### Description
Retrieves a specific prompt by its unique identifier, provided in the request body.
### Method
POST
### Endpoint
/get-prompt
### Request Body
- **id** (string) - Required - The unique identifier of the prompt to retrieve.
### Request Example
```json
{
"id": "your_prompt_id"
}
```
### Response
#### Success Response (200)
- **detail** (array) - An array of error details if the prompt is not found or an issue occurs during retrieval.
- **loc** (array) - Location of the error in the request.
- (string) - Required - Part of the location.
- (integer) - Required - Index within the location.
- **msg** (string) - Required - The error message.
- **type** (string) - Required - The type of error.
#### Response Example
```json
{
"detail": [
{
"loc": [
"string",
0
],
"msg": "string",
"type": "string"
}
]
}
```
```
--------------------------------
### Deploy Website Using SSH
Source: https://github.com/bytedance/sandboxfusion/blob/main/docs/README.md
Deploys the website using SSH, suitable for GitHub Pages hosting. Builds the site and pushes to the 'gh-pages' branch.
```bash
USE_SSH=true yarn deploy
```
--------------------------------
### Get Prompt by ID
Source: https://github.com/bytedance/sandboxfusion/blob/main/docs/docs/api/get-prompt-get-prompt-by-id-post.api.mdx
Fetches a prompt using its ID. The ID can be either an integer or a string.
```APIDOC
## POST /get-prompt-by-id
### Description
Retrieves a specific prompt by its unique identifier. The ID can be an integer or a string.
### Method
POST
### Endpoint
/get-prompt-by-id
### Request Body
- **id** (integer | string) - Required - The unique identifier of the prompt.
- **extra** (object) - Optional - Additional data for the request.
### Request Example
```json
{
"id": 123,
"extra": {}
}
```
### Response
#### Success Response (200)
- **id** (integer | string) - The unique identifier of the prompt.
- **extra** (object) - Additional data associated with the prompt.
```
--------------------------------
### Format Code
Source: https://github.com/bytedance/sandboxfusion/blob/main/README.md
Formats the project's code according to the defined style guidelines. This command ensures code consistency across the project.
```bash
make format
```
--------------------------------
### Get Task Result
Source: https://github.com/bytedance/sandboxfusion/blob/main/docs/docs/api/submit-submit-post.api.mdx
Retrieves the final result of a completed task using its unique task ID.
```APIDOC
## GET /result/{task_id}
### Description
Retrieves the complete result of a task once it has finished execution. This endpoint should only be called after confirming the task status is 'Finished'.
### Method
GET
### Endpoint
/result/{task_id}
### Parameters
#### Path Parameters
- **task_id** (string) - Required - The unique identifier of the task whose results are to be retrieved.
### Response
#### Success Response (200)
- **status** (string) - The final status of the task. Possible values: `Finished`, `Error`, `TimeLimitExceeded`.
- **message** (string) - A message indicating the outcome or any errors encountered.
- **compile_result** (object) - An object containing compilation details if applicable. This can be `CommandRunResult` or similar structure.
- **status** (string) - Possible values: `Finished`, `Error`, `TimeLimitExceeded`.
- **execution_time** (object) - Details about execution time.
#### Response Example
```json
{
"status": "Finished",
"message": "Task completed successfully.",
"compile_result": {
"status": "Finished",
"execution_time": {
"seconds": 0.123,
"nanos": 456000000
}
}
}
```
```
--------------------------------
### Get Task Status
Source: https://github.com/bytedance/sandboxfusion/blob/main/docs/docs/api/submit-submit-post.api.mdx
Retrieves the current status of a submitted task using its unique task ID.
```APIDOC
## GET /status/{task_id}
### Description
Retrieves the current status of a previously submitted task. This endpoint is used to monitor the progress of a task without retrieving its full output until completion.
### Method
GET
### Endpoint
/status/{task_id}
### Parameters
#### Path Parameters
- **task_id** (string) - Required - The unique identifier of the task to query.
### Response
#### Success Response (200)
- **status** (string) - The current status of the task. Possible values: `Pending`, `Queued`, `Running`, `Finished`, `Error`, `TimeLimitExceeded`.
- **message** (string) - A brief message providing additional context about the task's status.
#### Response Example
```json
{
"status": "Running",
"message": "Task is currently executing."
}
```
```
--------------------------------
### Get Prompt by ID
Source: https://github.com/bytedance/sandboxfusion/blob/main/docs/docs/api/get-prompt-get-prompt-by-id-post.api.mdx
Fetches a prompt using its ID. You can specify the dataset type and language for processing.
```APIDOC
## POST /get_prompt/{id}
### Description
Retrieves a specific prompt by its ID. This endpoint is used to fetch prompt details, allowing for custom extraction logic based on dataset type and language.
### Method
POST
### Endpoint
`/get_prompt/{id}`
### Parameters
#### Path Parameters
- **id** (string) - Required - The unique identifier of the prompt.
#### Request Body
- **dataset_type** (object) - Required - The dataset class used to process. Only works when the dataset id is not registered. Possible values include 'string'.
- **language** (object) - Required - Specifies the programming language for the prompt. Possible values include: [`python`, `cpp`, `nodejs`, `go`, `go_test`, `java`, `php`, `csharp`, `bash`, `typescript`, `sql`, `rust`, `cuda`, `lua`, `R`, `perl`, `D_ut`, `ruby`, `scala`, `julia`, `pytest`, `junit`, `kotlin_script`, `jest`, `verilog`, `python_gpu`, `lean`, `swift`, `racket`].
### Request Example
```json
{
"dataset_type": "string",
"language": "python"
}
```
### Response
#### Success Response (200)
- **prompt** (string) - The content of the prompt.
- **custom_extract_logic** (function) - A piece of python code that calls `submit_code_blocks(cbs)` to extract custom code.
#### Response Example
```json
{
"prompt": "def hello_world():\n print('Hello, world!')",
"custom_extract_logic": "def extract(cbs):\n submit_code_blocks(cbs)\n return 'extracted content'"
}
```
```
--------------------------------
### CRUXEval Dataset Configuration
Source: https://github.com/bytedance/sandboxfusion/blob/main/docs/docs/docs/how-to/use-dataset/cruxeval.mdx
Configure the CRUXEval dataset with options for mode, prompt wrapping, cot instructions, and model-specific prompts. Includes settings for compilation and execution timeouts.
```javascript
import DatasetSelector from '@site/src/components/DatasetSelector';
import { docWithType } from '@site/src/components/DatasetSelector/docGenerator';
```
--------------------------------
### Get Prompt By ID
Source: https://github.com/bytedance/sandboxfusion/blob/main/docs/docs/api/get-prompt-by-id-get-prompt-by-id-post.api.mdx
Fetches a prompt by its ID. This endpoint is designed to be called via a POST request.
```APIDOC
## POST /prompts/{id}
### Description
Retrieves a specific prompt by its unique identifier.
### Method
POST
### Endpoint
/prompts/{id}
### Parameters
#### Path Parameters
- **id** (string) - Required - The unique identifier of the prompt to retrieve.
### Response
#### Success Response (200)
- **detail** (array) - An array of error details if the prompt is not found or an issue occurs during retrieval.
- **loc** (array) - Location of the error within the request or response.
- (string) - The segment of the location.
- (integer) - The index within the segment.
- **msg** (string) - A message describing the error.
- **type** (string) - The type of error.
### Request Example
```json
{
"example": "request body"
}
```
### Response Example
#### Success Response (200)
```json
{
"detail": [
{
"loc": [
"string",
0
],
"msg": "string",
"type": "string"
}
]
}
```
```
--------------------------------
### List IDs for Selected Dataset
Source: https://github.com/bytedance/sandboxfusion/blob/main/sandbox/pages/oj.html
Fetches prompt IDs based on the selected dataset and configuration, then populates the ID select element. It also triggers fetching the prompt for the first ID.
```javascript
async function listIds() {
const dataset = document.getElementById('dataset').value;
const config = JSON.parse(document.getElementById('config').value);
const response = await axios.post(rewriteEndpoint('/list_ids'), {
dataset,
config
});
const ids = response.data;
const idSelect = document.getElementById('id');
idSelect.innerHTML = '';
ids.forEach(id => {
const option = document.createElement('option');
option.value = id;
option.textContent = id;
idSelect.appendChild(option);
});
getPrompt();
}
```
--------------------------------
### Get Prompt by ID
Source: https://github.com/bytedance/sandboxfusion/blob/main/docs/docs/api/get-prompt-by-id-get-prompt-by-id-post.api.mdx
This endpoint retrieves a prompt by its ID. It requires the prompt ID in the request body.
```APIDOC
## POST /get-prompt-by-id
### Description
Retrieves a specific prompt by its unique identifier.
### Method
POST
### Endpoint
/get-prompt-by-id
### Request Body
- **id** (string) - Required - The unique identifier of the prompt to retrieve.
- **run_timeout** (object) - Optional - Configuration for run timeout.
- **custom_extract_logic** (object) - Optional - Custom logic for data extraction.
- **provided_data** (object) - Optional - Data provided for the prompt.
### Request Example
```json
{
"id": "prompt_12345",
"run_timeout": {
"timeout": 60
},
"custom_extract_logic": {
"logic": "extract_all_text"
},
"provided_data": {
"key": "value"
}
}
```
### Response
#### Success Response (200)
- **prompt** (object) - The retrieved prompt object.
- **id** (string) - The unique identifier of the prompt.
- **content** (string) - The content of the prompt.
- **created_at** (string) - The timestamp when the prompt was created.
#### Response Example
```json
{
"prompt": {
"id": "prompt_12345",
"content": "What is the capital of France?",
"created_at": "2023-10-27T10:00:00Z"
}
}
```
```
--------------------------------
### Python Test for SQL Query
Source: https://github.com/bytedance/sandboxfusion/blob/main/docs/docs/docs/reference/dataset-detail/autoeval.md
This Python script uses pandas and pandasql to test the SQL query. It sets up sample user and order data, executes the SQL query, and asserts that the results match the expected minimum and maximum order amounts for different registration periods.
```python
import pandas as pd
import pandasql as ps
import io
users_data = '''
user_id,register_date
1,"2020-07-01"
2,"2020-07-12"
3,"2020-08-18"
4,"2020-08-20"
5,"2020-09-21"
6,"2020-09-25"
7,"2020-12-06"
8,"2021-01-15"
9,"2021-02-25"
10,"2021-03-25"
11,"2021-04-10"
12,"2021-05-20"
13,"2022-01-15"
14,"2022-05-08"
15,"2023-02-18"
16,"2023-05-07"
17,"2023-07-20"
'''
order_data = '''
user_id,order_id,order_date,order_amount
2,"a1","2020-07-13",188.5
3,"a2","2020-08-20",58.9
2,"a3","2020-08-21",36.5
4,"a4","2020-08-25",560.0
3,"a5","2020-09-20",35.9
5,"a6","2020-09-25",66.6
6,"a7","2020-09-27",380.0
9,"a8","2021-03-28",1090.0
5,"a9","2021-03-29",108.5
10,"a10","2021-04-20",66.4
12,"a11","2021-06-06",788.5
14,"a12","2022-06-10",46.5
15,"a13","2023-03-30",188.5
16,"a14","2023-06-29",78.9
17,"a15","2023-08-10",166.5
'''
users = pd.read_csv(io.StringIO(users_data))
orders = pd.read_csv(io.StringIO(order_data))
df = ps.sqldf("""#""")
expected_dates = {'2020-07', '2020-08', '2020-09', '2021-02', '2021-03', '2021-05', '2022-05', '2023-02', '2023-05', '2023-07'}
assert(set(df['reg_year_amount'].values).issubset(expected_dates))
assert(abs(df.loc[df['reg_year_amount'] == '2020-07']['min_order_amount'].iloc[0] - 36.5) < 1e-5)
assert(abs(df.loc[df['reg_year_amount'] == '2020-08']['max_order_amount'].iloc[0] - 560.0) < 1e-5)
assert(abs(df.loc[df['reg_year_amount'] == '2020-09']['max_order_amount'].iloc[0] - 380.0) < 1e-5)
```