Buckets:
| <meta charset="utf-8" /><meta name="hf:doc:metadata" content="{"title":"OpenCode Environment for OpenEnv","local":"opencode-environment-for-openenv","sections":[{"title":"Quick Start","local":"quick-start","sections":[{"title":"Async (default — talk to the deployed Space)","local":"async-default--talk-to-the-deployed-space","sections":[],"depth":3},{"title":"Sync wrapper","local":"sync-wrapper","sections":[],"depth":3},{"title":"In-process primitive (no HTTP)","local":"in-process-primitive-no-http","sections":[],"depth":3}],"depth":2},{"title":"Building the Docker Image","local":"building-the-docker-image","sections":[],"depth":2},{"title":"The MCP Tool: run_rollout","local":"the-mcp-tool-runrollout","sections":[],"depth":2},{"title":"Two Operating Modes","local":"two-operating-modes","sections":[],"depth":2},{"title":"Environment Variables","local":"environment-variables","sections":[],"depth":2},{"title":"Pre-baked E2B Template","local":"pre-baked-e2b-template","sections":[],"depth":2},{"title":"Project Structure","local":"project-structure","sections":[],"depth":2},{"title":"References","local":"references","sections":[],"depth":2}],"depth":1}"> | |
| <link href="/docs/openenv/pr_813/en/_app/immutable/assets/0.e3b0c442.css" rel="modulepreload"> | |
| <link rel="modulepreload" href="/docs/openenv/pr_813/en/_app/immutable/entry/start.9c9d6cdf.js"> | |
| <link rel="modulepreload" href="/docs/openenv/pr_813/en/_app/immutable/chunks/scheduler.2b22cead.js"> | |
| <link rel="modulepreload" href="/docs/openenv/pr_813/en/_app/immutable/chunks/singletons.b9e7e2c8.js"> | |
| <link rel="modulepreload" href="/docs/openenv/pr_813/en/_app/immutable/chunks/paths.4b396019.js"> | |
| <link rel="modulepreload" href="/docs/openenv/pr_813/en/_app/immutable/entry/app.b8b7485a.js"> | |
| <link rel="modulepreload" href="/docs/openenv/pr_813/en/_app/immutable/chunks/preload-helper.b21f837c.js"> | |
| <link rel="modulepreload" href="/docs/openenv/pr_813/en/_app/immutable/chunks/index.1a0e8013.js"> | |
| <link rel="modulepreload" href="/docs/openenv/pr_813/en/_app/immutable/nodes/0.93b1c108.js"> | |
| <link rel="modulepreload" href="/docs/openenv/pr_813/en/_app/immutable/chunks/each.e59479a4.js"> | |
| <link rel="modulepreload" href="/docs/openenv/pr_813/en/_app/immutable/nodes/26.60854602.js"> | |
| <link rel="modulepreload" href="/docs/openenv/pr_813/en/_app/immutable/chunks/MermaidChart.svelte_svelte_type_style_lang.f5f19e58.js"> | |
| <link rel="modulepreload" href="/docs/openenv/pr_813/en/_app/immutable/chunks/CodeBlock.640a2a71.js"><!-- HEAD_svelte-u9bgzb_START --><meta name="hf:doc:metadata" content="{"title":"OpenCode Environment for OpenEnv","local":"opencode-environment-for-openenv","sections":[{"title":"Quick Start","local":"quick-start","sections":[{"title":"Async (default — talk to the deployed Space)","local":"async-default--talk-to-the-deployed-space","sections":[],"depth":3},{"title":"Sync wrapper","local":"sync-wrapper","sections":[],"depth":3},{"title":"In-process primitive (no HTTP)","local":"in-process-primitive-no-http","sections":[],"depth":3}],"depth":2},{"title":"Building the Docker Image","local":"building-the-docker-image","sections":[],"depth":2},{"title":"The MCP Tool: run_rollout","local":"the-mcp-tool-runrollout","sections":[],"depth":2},{"title":"Two Operating Modes","local":"two-operating-modes","sections":[],"depth":2},{"title":"Environment Variables","local":"environment-variables","sections":[],"depth":2},{"title":"Pre-baked E2B Template","local":"pre-baked-e2b-template","sections":[],"depth":2},{"title":"Project Structure","local":"project-structure","sections":[],"depth":2},{"title":"References","local":"references","sections":[],"depth":2}],"depth":1}"><!-- HEAD_svelte-u9bgzb_END --> <p></p> <div class="items-center shrink-0 min-w-[100px] max-sm:min-w-[50px] justify-end ml-auto flex" style="float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"><div class="inline-flex rounded-md max-sm:rounded-sm"><button class="inline-flex items-center gap-1 h-7 max-sm:h-7 px-2 max-sm:px-1.5 text-sm font-medium text-gray-800 border border-r-0 rounded-l-md max-sm:rounded-l-sm border-gray-200 bg-white hover:shadow-inner dark:border-gray-850 dark:bg-gray-950 dark:text-gray-200 dark:hover:bg-gray-800" aria-live="polite"><span class="inline-flex items-center justify-center rounded-md p-0.5 max-sm:p-0 hover:text-gray-800 dark:hover:text-gray-200"><svg class="sm:size-3.5 size-3" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg></span> <span>Copy page</span></button> <button class="inline-flex items-center justify-center w-6 max-sm:w-5 h-7 max-sm:h-7 disabled:pointer-events-none text-sm text-gray-500 hover:text-gray-700 dark:hover:text-white rounded-r-md max-sm:rounded-r-sm border border-l transition border-gray-200 bg-white hover:shadow-inner dark:border-gray-850 dark:bg-gray-950 dark:text-gray-200 dark:hover:bg-gray-800" aria-haspopup="menu" aria-expanded="false" aria-label="Open copy menu"><svg class="transition-transform text-gray-400 overflow-visible sm:size-3.5 size-3 rotate-0" width="1em" height="1em" viewBox="0 0 12 7" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1 1L6 6L11 1" stroke="currentColor"></path></svg></button></div> </div> <h1 class="relative group"><a id="opencode-environment-for-openenv" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#opencode-environment-for-openenv"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>OpenCode Environment for OpenEnv</span></h1> <p data-svelte-h="svelte-ws0r3i"><code>opencode_env</code> runs the <a href="https://opencode.ai" rel="nofollow">OpenCode</a> coding agent inside | |
| an isolated <a href="https://e2b.dev" rel="nofollow">E2B</a> sandbox against any OpenAI-compatible | |
| LLM endpoint, optionally capturing per-token logprobs for GRPO training.</p> <p data-svelte-h="svelte-16wusqa"><strong>🚀 Try it live</strong>: <a href="https://huggingface.co/spaces/AdithyaSK/opencode-env" rel="nofollow"><code>AdithyaSK/opencode-env</code></a></p> <p data-svelte-h="svelte-tv5fsm">The deployed Space exposes:</p> <ul data-svelte-h="svelte-ubj6gt"><li><strong>Web UI</strong> at <a href="https://adithyask-opencode-env.hf.space/web" rel="nofollow"><code>/web</code></a> — pick endpoint, write task, hit Run, watch live phase log + reward + logprobs.</li> <li><strong>MCP tool API</strong> at <a href="https://adithyask-opencode-env.hf.space/mcp" rel="nofollow"><code>/mcp</code></a> — programmatic <code>run_rollout</code> calls.</li> <li><strong>OpenAPI docs</strong> at <a href="https://adithyask-opencode-env.hf.space/docs" rel="nofollow"><code>/docs</code></a>.</li> <li><strong>Health</strong> at <a href="https://adithyask-opencode-env.hf.space/health" rel="nofollow"><code>/health</code></a>.</li></ul> <p data-svelte-h="svelte-1yi0elf">The env is <strong>task-agnostic</strong> — every rollout is configured at call-time | |
| with a uniform Task shape:</p> <ul data-svelte-h="svelte-vcps8v"><li><strong><code>instruction</code></strong> — prompt for the agent</li> <li><strong><code>setup</code></strong> — list of bash commands run <em>before</em> the agent (pip | |
| install, git clone, file downloads — anything you need staged in the | |
| sandbox)</li> <li><strong><code>verify</code></strong> — list of bash commands run <em>after</em> the agent (asserts, | |
| pytest invocations, score-file writes)</li></ul> <p data-svelte-h="svelte-1p6htkq">Reward = <code>passed_verify / total_verify</code> unless any <code>verify</code> command writes | |
| a float to <code>/home/user/logs/verifier/reward.txt</code> (override).</p> <h2 class="relative group"><a id="quick-start" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#quick-start"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Quick Start</span></h2> <h3 class="relative group"><a id="async-default--talk-to-the-deployed-space" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#async-default--talk-to-the-deployed-space"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Async (default — talk to the deployed Space)</span></h3> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class="language-python "><!-- HTML_TAG_START --><span class="hljs-keyword">import</span> asyncio | |
| <span class="hljs-keyword">import</span> os | |
| <span class="hljs-keyword">from</span> opencode_env <span class="hljs-keyword">import</span> OpenCodeEnv | |
| <span class="hljs-keyword">from</span> opencode_env.client <span class="hljs-keyword">import</span> _extract_text | |
| <span class="hljs-keyword">from</span> opencode_env.models <span class="hljs-keyword">import</span> RolloutResult | |
| <span class="hljs-keyword">async</span> <span class="hljs-keyword">def</span> <span class="hljs-title function_">main</span>(): | |
| SPACE = <span class="hljs-string">"https://adithyask-opencode-env.hf.space"</span> | |
| <span class="hljs-keyword">async</span> <span class="hljs-keyword">with</span> OpenCodeEnv(base_url=SPACE) <span class="hljs-keyword">as</span> env: | |
| <span class="hljs-keyword">await</span> env.reset() | |
| <span class="hljs-comment"># The MCP tool returns JSON; deserialize via the typed model.</span> | |
| raw = <span class="hljs-keyword">await</span> env.call_tool( | |
| <span class="hljs-string">"run_rollout"</span>, | |
| endpoint=<span class="hljs-string">"openai"</span>, <span class="hljs-comment"># vllm | openai | hf_router</span> | |
| api_key=os.environ[<span class="hljs-string">"OPENAI_API_KEY"</span>], <span class="hljs-comment"># or set as a Space secret</span> | |
| instruction=( | |
| <span class="hljs-string">"Create binary_search.py exposing def binary_search(arr, target) -> int "</span> | |
| <span class="hljs-string">"that returns the index of target in arr, or -1 if absent. Use a "</span> | |
| <span class="hljs-string">"relative path."</span> | |
| ), | |
| setup=[], | |
| verify=[ | |
| <span class="hljs-string">"test -f /home/user/workdir/binary_search.py"</span>, | |
| <span class="hljs-string">"python -c \"import sys; sys.path.insert(0, '/home/user/workdir'); "</span> | |
| <span class="hljs-string">"import binary_search; "</span> | |
| <span class="hljs-string">"assert binary_search.binary_search([1,2,3], 2) == 1; print('OK')\""</span>, | |
| ], | |
| template=<span class="hljs-string">"opencode-rl"</span>, <span class="hljs-comment"># prebaked E2B template</span> | |
| task_id=<span class="hljs-string">"binary_search_v1"</span>, | |
| ) | |
| result = RolloutResult.model_validate_json(_extract_text(raw)) | |
| <span class="hljs-built_in">print</span>(<span class="hljs-string">"reward:"</span>, result.reward) | |
| <span class="hljs-built_in">print</span>(<span class="hljs-string">"turns:"</span>, <span class="hljs-built_in">len</span>(result.proxy_turns)) | |
| <span class="hljs-built_in">print</span>(<span class="hljs-string">"files:"</span>, <span class="hljs-built_in">list</span>(result.files.keys())) | |
| <span class="hljs-built_in">print</span>(<span class="hljs-string">"wall:"</span>, result.wall_s, <span class="hljs-string">"s"</span>) | |
| asyncio.run(main())<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1rssvp6">Expected output (~20s with the prebaked template):</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=" "><!-- HTML_TAG_START --><span class="hljs-attribute">reward</span>: <span class="hljs-number">1</span>.<span class="hljs-number">0</span> | |
| <span class="hljs-attribute">turns</span>: <span class="hljs-number">3</span> | |
| <span class="hljs-attribute">files</span>:<span class="hljs-meta"> ['/home/user/workdir/binary_search.py', ...]</span> | |
| <span class="hljs-attribute">wall</span>: <span class="hljs-number">19</span>.<span class="hljs-number">8</span> s<!-- HTML_TAG_END --></pre></div> <h3 class="relative group"><a id="sync-wrapper" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#sync-wrapper"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Sync wrapper</span></h3> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class="language-python "><!-- HTML_TAG_START --><span class="hljs-keyword">import</span> os | |
| <span class="hljs-keyword">from</span> opencode_env <span class="hljs-keyword">import</span> OpenCodeEnv | |
| <span class="hljs-comment"># .sync() returns a synchronous wrapper around the async client.</span> | |
| <span class="hljs-keyword">with</span> OpenCodeEnv(base_url=<span class="hljs-string">"https://adithyask-opencode-env.hf.space"</span>).sync() <span class="hljs-keyword">as</span> env: | |
| env.reset() | |
| <span class="hljs-comment"># MCP tools are reachable via env.call_tool(...) / env.step(...) sync-wrapped.</span> | |
| <span class="hljs-comment"># See the async example above for the full run_rollout signature.</span><!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1yys0lj">Point <code>base_url</code> at <code>http://localhost:8000</code> to talk to a local container | |
| instead of the public Space.</p> <h3 class="relative group"><a id="in-process-primitive-no-http" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#in-process-primitive-no-http"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>In-process primitive (no HTTP)</span></h3> <p data-svelte-h="svelte-y4m68a">For trainers that want to drive a sandbox directly without an HTTP boundary:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class="language-python "><!-- HTML_TAG_START --><span class="hljs-keyword">import</span> os | |
| <span class="hljs-keyword">from</span> opencode_env <span class="hljs-keyword">import</span> ( | |
| OpenCodeConfig, OpenCodeSessionFactory, OpenCodeTask, E2BSandboxBackend, | |
| ) | |
| factory = OpenCodeSessionFactory( | |
| config=OpenCodeConfig( | |
| provider=<span class="hljs-string">"openai_compatible"</span>, | |
| base_url=<span class="hljs-string">"https://api.openai.com/v1"</span>, | |
| api_key=os.environ[<span class="hljs-string">"OPENAI_API_KEY"</span>], | |
| model=<span class="hljs-string">"gpt-4o-mini"</span>, | |
| ), | |
| sandbox_backend=E2BSandboxBackend(), | |
| mode=<span class="hljs-string">"transparent_proxy"</span>, <span class="hljs-comment"># captures per-token logprobs</span> | |
| ) | |
| session = factory.create(task=OpenCodeTask(instruction=<span class="hljs-string">"..."</span>)) | |
| session.wait_for_completion() | |
| turns = session.fetch_proxy_trace() <span class="hljs-comment"># per-turn (tokens, logprobs)</span> | |
| session.close()<!-- HTML_TAG_END --></pre></div> <h2 class="relative group"><a id="building-the-docker-image" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#building-the-docker-image"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Building the Docker Image</span></h2> <p data-svelte-h="svelte-6qcq2s">The Dockerfile lives at <code>server/Dockerfile</code>. Use the <code>openenv</code> CLI from | |
| the env root:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class="language-bash "><!-- HTML_TAG_START --><span class="hljs-built_in">cd</span> envs/opencode_env | |
| openenv validate <span class="hljs-comment"># check pyproject.toml + openenv.yaml + server/app.py + uv.lock</span> | |
| openenv build -t opencode-env <span class="hljs-comment"># builds the image (uses server/Dockerfile)</span> | |
| <span class="hljs-comment"># run locally with E2B credentials</span> | |
| docker run -p 8000:8000 -e E2B_API_KEY=e2b_... opencode-env | |
| <span class="hljs-comment"># push to HF Spaces (Docker variant)</span> | |
| openenv push --repo-id <user>/opencode-env<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1rcspm2">Or build directly without the CLI:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class="language-bash "><!-- HTML_TAG_START -->docker build -t opencode-env -f envs/opencode_env/server/Dockerfile envs/opencode_env<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-hk5w0o">The image:</p> <ul data-svelte-h="svelte-1pbyowd"><li>Runs <code>uvicorn server.app:app --host 0.0.0.0 --port 8000</code></li> <li>Exposes the MCP API at <code>/mcp</code> and <code>/step</code>, the Gradio UI at <code>/web</code>, | |
| health at <code>/health</code>, and OpenAPI docs at <code>/docs</code>.</li> <li>Reads <code>E2B_API_KEY</code> and (optionally) endpoint-specific env vars at | |
| runtime (see <a href="#environment-variables">Environment Variables</a>).</li></ul> <h2 class="relative group"><a id="the-mcp-tool-runrollout" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#the-mcp-tool-runrollout"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>The MCP Tool: run_rollout</span></h2> <p data-svelte-h="svelte-bhhnj1">Single tool, two ways to specify the LLM endpoint:</p> <p data-svelte-h="svelte-112hxck"><strong>Option A — endpoint shorthand (recommended)</strong>: pass | |
| <code>endpoint="vllm"</code> (or <code>"openai"</code> / <code>"hf_router"</code>). The server resolves | |
| <code>base_url</code>, <code>api_key</code>, and <code>model</code> from env vars + catalog defaults. | |
| Any explicit field overrides the catalog.</p> <p data-svelte-h="svelte-1qyvon2"><strong>Option B — fully explicit</strong>: pass <code>base_url</code> + <code>api_key</code> + <code>model</code> | |
| directly.</p> <table data-svelte-h="svelte-1jd3xp6"><thead><tr><th>Arg</th> <th>Type</th> <th>Default</th> <th>Notes</th></tr></thead> <tbody><tr><td><code>endpoint</code></td> <td><code>str</code></td> <td><code>""</code></td> <td>One of <code>"vllm"</code> / <code>"openai"</code> / <code>"hf_router"</code>.</td></tr> <tr><td><code>base_url</code> / <code>api_key</code> / <code>model</code></td> <td><code>str</code></td> <td><code>""</code></td> <td>Override / supply explicitly.</td></tr> <tr><td><code>instruction</code></td> <td><code>str</code></td> <td>required</td> <td>Prompt passed to <code>opencode run</code>.</td></tr> <tr><td><code>setup</code></td> <td><code>list[str]</code></td> <td><code>[]</code></td> <td>Bash commands run <strong>before</strong> the agent.</td></tr> <tr><td><code>verify</code></td> <td><code>list[str]</code></td> <td><code>[]</code></td> <td>Bash commands run <strong>after</strong> the agent.</td></tr> <tr><td><code>task_id</code></td> <td><code>str</code></td> <td><code>""</code></td> <td>Echoed back in result.</td></tr> <tr><td><code>mode</code></td> <td><code>str</code></td> <td><code>"transparent_proxy"</code></td> <td>Or <code>"black_box"</code> (no logprobs).</td></tr> <tr><td><code>disable_thinking</code></td> <td><code>bool \| None</code></td> <td><code>None</code> (catalog default)</td> <td>Inject <code>chat_template_kwargs.enable_thinking=false</code>.</td></tr> <tr><td><code>max_tokens_cap</code></td> <td><code>int</code></td> <td><code>4096</code></td> <td>Per-turn <code>max_tokens</code> clamp.</td></tr> <tr><td><code>top_logprobs</code></td> <td><code>int</code></td> <td><code>5</code></td> <td>HF Router cap is 5; OpenAI 0–20; vLLM unbounded.</td></tr> <tr><td><code>agent_timeout_s</code></td> <td><code>float</code></td> <td><code>600.0</code></td> <td>Hard wall budget for opencode.</td></tr> <tr><td><code>template</code></td> <td><code>str</code></td> <td><code>""</code></td> <td>E2B template name; <code>"opencode-rl"</code> skips ~2 min of install per rollout.</td></tr></tbody></table> <p data-svelte-h="svelte-1kopt96">Returns <code>RolloutResult</code> JSON with: <code>reward</code>, <code>setup_results[]</code>, | |
| <code>verify_results[]</code>, <code>proxy_turns[]</code>, <code>files{}</code>, <code>agent_log_tail</code>, | |
| <code>proxy_log_tail</code>, <code>wall_s</code>, <code>agent_exit_code</code>, <code>sandbox_id</code>, <code>error</code>.</p> <h2 class="relative group"><a id="two-operating-modes" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#two-operating-modes"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Two Operating Modes</span></h2> <table data-svelte-h="svelte-82gzuy"><thead><tr><th>Mode</th> <th>What it does</th> <th>Best for</th></tr></thead> <tbody><tr><td><strong><code>transparent_proxy</code></strong> (default)</td> <td>In-sandbox proxy at <code>localhost:7000</code> forwards opencode’s LLM calls to <code>base_url</code>, injects <code>logprobs=true</code>, captures per-turn <code>(messages, completion_tokens, logprobs)</code> to <code>proxy_trace.jsonl</code>.</td> <td>GRPO / RL training, observability, top-k distillation.</td></tr> <tr><td><strong><code>black_box</code></strong></td> <td>No proxy. opencode talks straight to <code>base_url</code>.</td> <td>Smoke tests, eval, SFT data collection.</td></tr></tbody></table> <h2 class="relative group"><a id="environment-variables" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#environment-variables"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Environment Variables</span></h2> <p data-svelte-h="svelte-pftksa">The server reads these at runtime. Local dev auto-loads them from a | |
| sibling <code>.env</code> file; on HF Spaces, set them as <strong>Space secrets</strong>.</p> <table data-svelte-h="svelte-7zvcm8"><thead><tr><th>Variable</th> <th>Required</th> <th>Purpose</th></tr></thead> <tbody><tr><td><code>E2B_API_KEY</code></td> <td><strong>yes</strong> for any rollout</td> <td>E2B sandbox credentials.</td></tr> <tr><td><code>MAX_CONCURRENT_ENVS</code></td> <td>no</td> <td>Env-instance pool size. Default <code>4</code>.</td></tr> <tr><td><code>ENABLE_WEB_INTERFACE</code></td> <td>no</td> <td>Set <code>false</code> to disable the <code>/web</code> Gradio mount. Default <code>true</code>.</td></tr> <tr><td><strong>vLLM endpoint</strong></td> <td></td> <td></td></tr> <tr><td><code>VLLM_URL</code></td> <td>required for <code>endpoint="vllm"</code></td> <td>OAI-compatible base URL.</td></tr> <tr><td><code>VLLM_API_KEY</code></td> <td>no</td> <td>Defaults to <code>intercepted</code>.</td></tr> <tr><td><code>VLLM_MODEL</code></td> <td>no</td> <td>Defaults to <code>Qwen/Qwen3.5-4B</code>.</td></tr> <tr><td><strong>OpenAI endpoint</strong></td> <td></td> <td></td></tr> <tr><td><code>OPENAI_API_KEY</code></td> <td>required for <code>endpoint="openai"</code></td> <td>Standard OpenAI key.</td></tr> <tr><td><code>OPENAI_BASE_URL</code></td> <td>no</td> <td>Defaults to <code>https://api.openai.com/v1</code>.</td></tr> <tr><td><code>OPENAI_MODEL</code></td> <td>no</td> <td>Defaults to <code>gpt-4o-mini</code> (gpt-5.x and o-series refuse logprobs).</td></tr> <tr><td><strong>HF Router endpoint</strong></td> <td></td> <td></td></tr> <tr><td><code>HF_ROUTER_API_KEY</code></td> <td>required for <code>endpoint="hf_router"</code></td> <td>HF user token.</td></tr> <tr><td><code>HF_ROUTER_BASE_URL</code></td> <td>no</td> <td>Defaults to <code>https://router.huggingface.co/v1</code>.</td></tr> <tr><td><code>HF_ROUTER_MODEL</code></td> <td>no</td> <td>Defaults to <code>Qwen/Qwen3-4B-Instruct-2507:nscale</code>.</td></tr></tbody></table> <p data-svelte-h="svelte-s8muzu">Pick <code>provider:</code> suffixes that actually return logprobs: | |
| <strong>Together / Nscale / Scaleway / SambaNova / Cerebras</strong>. Avoid Novita / | |
| Hyperbolic / Featherless (silent drop) and Groq (HTTP 400).</p> <h2 class="relative group"><a id="pre-baked-e2b-template" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#pre-baked-e2b-template"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Pre-baked E2B Template</span></h2> <p data-svelte-h="svelte-1xhdcbd">The first rollout in a fresh E2B sandbox spends ~2 min installing | |
| opencode and the proxy’s Python deps. Build a one-time template that | |
| ships those pre-installed:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class="language-bash "><!-- HTML_TAG_START -->.venv/bin/python envs/opencode_env/sandbox/build_template.py | |
| <span class="hljs-comment"># → builds `opencode-rl` template in your E2B account (~1m20s, one-time)</span><!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-z2r2io">After this, pass <code>template="opencode-rl"</code> on every <code>run_rollout</code> call — | |
| each rollout drops to ~20–30s end-to-end.</p> <h2 class="relative group"><a id="project-structure" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#project-structure"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Project Structure</span></h2> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=" "><!-- HTML_TAG_START -->opencode_env/ | |
| ├── README.md <span class="hljs-comment"># this file</span> | |
| ├── openenv.yaml <span class="hljs-comment"># OpenEnv space spec</span> | |
| ├── pyproject.toml <span class="hljs-comment"># deps + ``server`` entrypoint</span> | |
| ├── uv.lock <span class="hljs-comment"># frozen deps (required by ``openenv validate``)</span> | |
| ├── .gitignore / .dockerignore <span class="hljs-comment"># excludes .env / __pycache__</span> | |
| ├── __init__.py <span class="hljs-comment"># re-exports primitive + client + models</span> | |
| │ | |
| ├── client.py <span class="hljs-comment"># OpenCodeEnv(MCPToolClient)</span> | |
| ├── models.py <span class="hljs-comment"># RolloutResult / RolloutTurn / OpenCodeState</span> | |
| │ | |
| ├── config.py <span class="hljs-comment"># OpenCodeConfig (primitive)</span> | |
| ├── harness.py <span class="hljs-comment"># OpenCodeSession / OpenCodeSessionFactory (CLI-only)</span> | |
| ├── opencode_runtime.py <span class="hljs-comment"># opencode.json builder + cmds</span> | |
| ├── task.py <span class="hljs-comment"># OpenCodeTask</span> | |
| │ | |
| ├── server/ | |
| │ ├── __init__.py | |
| │ ├── app.py <span class="hljs-comment"># FastAPI factory; mounts Gradio at /web</span> | |
| │ ├── opencode_environment.py <span class="hljs-comment"># MCPEnvironment with single ``run_rollout`` tool</span> | |
| │ ├── gradio_ui.py <span class="hljs-comment"># the /web Gradio Blocks UI</span> | |
| │ ├── catalog.py <span class="hljs-comment"># endpoint shorthand resolver</span> | |
| │ └── Dockerfile <span class="hljs-comment"># multi-stage uv build (used by ``openenv build``)</span> | |
| │ | |
| └── sandbox/ | |
| ├── __init__.py | |
| ├── base.py <span class="hljs-comment"># SandboxBackend / SandboxHandle Protocols</span> | |
| ├── e2b.py <span class="hljs-comment"># E2B implementation</span> | |
| ├── interception.py <span class="hljs-comment"># in-sandbox FastAPI proxy (logprob capture)</span> | |
| └── build_template.py <span class="hljs-comment"># one-time E2B template builder</span><!-- HTML_TAG_END --></pre></div> <h2 class="relative group"><a id="references" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#references"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>References</span></h2> <ul data-svelte-h="svelte-351eyz"><li><a href="https://huggingface.co/docs/openenv" rel="nofollow">OpenEnv docs</a></li> <li><a href="https://opencode.ai/docs/cli/" rel="nofollow">OpenCode CLI</a></li> <li><a href="https://e2b.dev/docs" rel="nofollow">E2B Python SDK</a></li> <li><a href="../../../DOCS/HF/hf_inference_providers_logprobs">HF Inference Providers logprob matrix</a></li></ul> <a class="!text-gray-400 !no-underline text-sm flex items-center not-prose mt-4" href="https://github.com/huggingface/openenv/blob/main/docs/source/environments/opencode.md" target="_blank"><svg class="mr-1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M31,16l-7,7l-1.41-1.41L28.17,16l-5.58-5.59L24,9l7,7z"></path><path d="M1,16l7-7l1.41,1.41L3.83,16l5.58,5.59L8,23l-7-7z"></path><path d="M12.419,25.484L17.639,6.552l1.932,0.518L14.351,26.002z"></path></svg> <span data-svelte-h="svelte-zjs2n5"><span class="underline">Update</span> on GitHub</span></a> <p></p> | |
| <script> | |
| { | |
| __sveltekit_1l28dw0 = { | |
| assets: "/docs/openenv/pr_813/en", | |
| base: "/docs/openenv/pr_813/en", | |
| env: {} | |
| }; | |
| const element = document.currentScript.parentElement; | |
| const data = [null,null]; | |
| Promise.all([ | |
| import("/docs/openenv/pr_813/en/_app/immutable/entry/start.9c9d6cdf.js"), | |
| import("/docs/openenv/pr_813/en/_app/immutable/entry/app.b8b7485a.js") | |
| ]).then(([kit, app]) => { | |
| kit.start(app, element, { | |
| node_ids: [0, 26], | |
| data, | |
| form: null, | |
| error: null | |
| }); | |
| }); | |
| } | |
| </script> | |
Xet Storage Details
- Size:
- 50.2 kB
- Xet hash:
- 7d328c83873134cf89836d3c7e6ea99c964d87f25a6979da7a28b2b4a785e23e
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.